Question

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? enter image description here

2)I have saved my features as "feature1...feature5" enter image description here

3)Here is the output of the feature1 enter image description here

4)Here is the list of my features (features1..5 can be seen here) enter image description here

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top