saving results as a table

Hi guys,
After doing my analysis with multiple files, using this code:
myDir = uigetdir; %gets directory
myFiles = dir(fullfile(myDir,'*.txt')); %gets all txt files in struct
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
num = importdata(fullFileName); %or readtable
end
I managed to get the desired results in no time. But, there is a problem with the output, which is not structured, something like this:
Now reading C:\...\file1.txt
result1 =
0.5041
result2 =
-0.0212
Now reading C:\...\file3.txt
result1 =
0.767
result2 =
0.323
Is there a more efficient way to visualize or perhaps store the results in a single file sorted by the file name and results? There are about 320 results, which I would have to manually rearrange if I don't solve this in Matlab.
Thanks

回答(1 个)

I think the code becomes like this.
N = length(myFiles);
baseFileName = cell(N,1);
result1 = zeros(N,1);
result2 = zeros(N,1);
for k = 1:N
baseFileName{k} = myFiles(k).name;
result1(k) = ****; % <- put your process which returns result1
result2(k) = ****; % <- put your process which returns result2
end
% Summarize in one table
T = table(baseFileName,result1,result2);
% Sort by file name
T = sortrows(T,'baseFileName');

类别

帮助中心File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by