Save data from a for loop in the same file

2 views (last 30 days)
In the following code, with a for loop , I want to save all the values of T in the same file, actually it save each value in a different file. T is inside a for loop. I want the values in the same file to process it, thanks!
clear all; close all;
im_geo=imread('background.jpg');
figure; imshow(im_geo), title('background'); % Background
hold on
im_geoo=imread('signal imatge ac 15052014.jpg');
figure; imshow(im_geoo), title('bright line'); % Bright line
z=1;
x= linspace(0, 35, 35);
%totes les línies de la imatge
for p=170:1:350;
z=z+1; %eix x
%valors I
t=im_geoo(p:p,271:306);
u=im_geo(p:p,271:306);
tu=t-u;
%fwhm
mi= min(tu); ma= max(tu);
x_above= x(tu> (ma- mi)/ 2);
fwhm= x_above(end)- x_above(1);
%paràmetres
a=atan(69./(2.*570));
mmpx=5./102;
m=fwhm.*mmpx;
T=(sqrt(2).*a.*m)./(3e11);
name = num2str(p) ;
filename = mat2str([name '.txt']);
save(filename, 'T', '-ascii','-double','-append');
%plot (z,T)
%hold on
end

Accepted Answer

Mahdi
Mahdi on 21 May 2014
I know there is a way to do it, but my brain is failing me at the moment. What you can do instead is hold all the T values in a matrix and then save that matrix:
i=1
for p=170:1:350
...
T(i)=(sqrt(2).*a.*m)./(3e11);
...
i=i+1;
end
filename="Put a filename here";
save(filename, 'T', '-ascii','-double','-append');
  1 Comment
Albert
Albert on 21 May 2014
yeah, I'm new in matlab and i don't know a lot of things yet. Thank you a lot.

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!