save output of for loop per row in new file

1 view (last 30 days)
ckoolschijn
ckoolschijn on 6 Aug 2014
Commented: Adam on 6 Aug 2014
hi all,
not so much experience with matlab commandline yet, and I'm experiencing problems with a simple save command. I have a for loop, and after a number of calculations output is created. For each subjects' output, I want to write the output to a new row in a matfile (structure created).
%script
subject_list={'C1,'C2','C3'};
numsubjects = length(subject_list);
ALL = struct([]);
CURRENT_thickness = 0;
for s=1:numsubjects
subject = subject_list{s};
fprintf('\n\n\n*** Processing subject %d (%s) *\n\n\n', s, subject);
inner=readdfs([subject '.inner_skull.dfs']);
outer=readdfs([subject '.outer_skull.dfs']);
ind=dsearchn(inner.vertices,outer.vertices);
thickness=sqrt(sum(inner.vertices(ind,:)-outer.vertices).^2.2); %thickness in 3 columns
CURRENT_thickness = CURRENT_thickness + 1;
=> need to save thickness output to matfile, see below for things tried
end
things I tried:
- ALL(CURRENT_thickness)=thickness; % error=>Assignment between unlike types is not allowed.
- save('ALL','thickness','-append'); % error => overwrites all previous info
- save with -ascii extension. this works, but excludes imaginary information
any suggestions would be much appreciated
Best Cédric
  1 Comment
Adam
Adam on 6 Aug 2014
Do you actually mean a matfile or just a .mat file? A matfile is something that you access on disk as though it were in memory.
If you mean just an ordinary matfile then I think you would have to load in the existing .mat file and add your results into it and save again in the loop, but being careful to ensure the variable names you use in the matfile are not the ones containing your new data to save otherwise when you load the .mat file it will overwrite the workspace variables.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!