Reputation: 187
How can I output values from variables from the workspace into a text file on MATLAB.
1)How do I get the output as below?
2)I have saved my features as "feature1...feature5"
3)Here is the output of the feature1
4)Here is the list of my features (features1..5 can be seen here)
Upvotes: 1
Views: 180
Reputation: 221574
Gather all feature variables into one variable and write to an ASCII delimited file.
Code -
feature = [feature1 feature2 feature3 feature4 feature5];
dlmwrite('myfile.txt', '', 'delimiter', '');
for c2 = 1:size(feature,1)
str1=[ num2str(median(feature(c2,:)))];
for c1 = 1:size(feature,2)
str1 =[str1 [' feature',num2str(c1),':' num2str(feature(c2,c1))] ];
end
dlmwrite('myfile.txt', str1, 'delimiter', '','-append');
end
The text file would look like this :
1 feature1:1 feature2:1 feature3:1 feature4:0 feature5:1
0 feature1:0 feature2:1 feature3:0 feature4:1 feature5:-1
0 feature1:1 feature2:0 feature3:0 feature4:1 feature5:-1
0 feature1:0 feature2:0 feature3:0 feature4:1 feature5:1
0 feature1:1 feature2:0 feature3:0 feature4:0 feature5:-1
1 feature1:1 feature2:0 feature3:1 feature4:1 feature5:1
0 feature1:0 feature2:0 feature3:0 feature4:1 feature5:-1
Please confirm if this is what you need!
Upvotes: 1