- Good idea: Rather than sending those concatenated strings to "eval", breakpoint your code, see what those string look like. Copy and paste those commands by hand into the command window, and see if they work. (Looks like you might be missing whitespace around the load and save keywords.)
- Better idea: Don't use "eval" at all. Use the functional form of the load and save commands (see the help file for syntax), that allow you to input strings for file names and variables.
loading and saving with eval using sprintf
25 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
the cyclist
2011 年 4 月 8 日
It's hard to know if there is a syntax error, without knowing what the variables "findex" and "tindex" are.
I have two suggestions:
If these work out for you, please accept this answer. If not, then next time you comment please tell us what "findex" and "tindex" are, and also give us the exact text of the error message(s) you are getting.
3 件のコメント
その他の回答 (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 件のコメント
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'});
参考
カテゴリ
Help Center および File Exchange で Model Type and Other Transformations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!