Save data from a for loop in the same file
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Mahdi
2014-5-21
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');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!