loading and saving with eval using sprintf
이전 댓글 표시
Hi, i am solving a non-linear ode problem and getting errors on running the code at following points:
Initially at
fname=sprintf('ts32/f%d',findex);
eval(['load' fname]);
and at end of code at
s=sprintf('ts32/f%dt%d',findex,tindex);
eval(['save' s 't x output load_torque load_force height mu force tanforce theta dt w j k l m n'])
As i am new to matlab can someone please guide as to if there is any error in the syntax
Thanks in advance
채택된 답변
추가 답변 (2개)
Robert Cumming
2011년 4월 8일
why dont you just do:
fname = fullfile ( directory, filename )
load ( fname )
then use similar at the end for saving:
fname = fullfile ( dir, savename )
save ( fname, 'variable' );
Ashraf Rayed
2020년 5월 12일
편집: Walter Roberson
2020년 5월 12일
i have this code, i have to check the leaf area of some pictures in a folder and then i have save the area of those leaves by sequence in an excel sheet. Can you plkease help to sort out the problem?
D = 'F:\MATLAB\R2018a\bin\rayed mat lab\experimental';
S = dir(fullfile(D,'*.jpg'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
I = imread(F);
ih=rgb2hsv(I);
ih1=ih(:,:,1);
binary=ih1>0.6;
leafArea = sum(binary(:))
subplot(2, 2, 2);
imshow(binary, []);
message = sprintf('The leaf area = %d pixels.\n pixels = %.1f%%',...
leafArea, defectArea/leafArea*100);
uiwait(msgbox(message))
end
댓글 수: 5
Walter Roberson
2020년 5월 12일
What difficulty are you encountering?
binary=ih1>0.6;
I would think you should put an upper bound on that as well, ih1>0.6 & ih1 < something
Ashraf Rayed
2020년 5월 12일
no problem with the code sir. I have to get the data which are calculted by the code of several images in a excel sequencially. Are you clear now?
Walter Roberson
2020년 5월 12일
Store the results from any one iteration into a variable indexed at k . Then after the loop, write that variable to an excel sheet, possibly together with the file names.
T = table({S.name}.', leafAreas(:), leafFractions(:), 'VariableNames', {'FileName', 'Area', 'Fraction'});
writetable(T, 'leaf_stats.xlsx');
Ashraf Rayed
2020년 5월 12일
It is not working to save all the data in the sheet even it is not to create any sheet also
Ashraf Rayed
2020년 5월 12일
showing this messege====
Undefined function or variable 'leafFractions'.
Error in Untitled (line 20)
T = table({S.name}.', leafArea(:), leafFractions(:), ('VariableNames'), {'FileName', 'Area', 'Fraction'});
카테고리
도움말 센터 및 File Exchange에서 State-Space Control Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!