Hi,
How to use sprintf when the Address parameter contains an array cell?
Address={'./DataBase/1/(%d).png','./DataBase/2/ (%d).png' , './DataBase/3/(%d).png','...........','./DataBase/10/(%d).png'}
for j=1:10
Address=Address(j);
end
S{i}=sprintf(Address,i);
.
.
.
When I use this code, I get the following error :
Error using sprintf
Invalid format.Error in LoadData (line 29)
S{i}=sprintf(Address,i);
thank you

3 件のコメント

Walter Roberson
Walter Roberson 2019 年 4 月 25 日
You are replacing the cell Address with () indexed elements of itself which would fail because after the first time it would be a scalar cell.
You try to pass a scalar cell as the format instead of using {} indexing to get the content.
Stephen23
Stephen23 2019 年 4 月 25 日
Writing out all of those format strings in the cell array is a waste of time anyway: it is better to generate them in the loop, exactly as madhan ravi showed.
Elahe Karimi
Elahe Karimi 2019 年 4 月 25 日
Thanks for the suggestions. I did it and the code does not make a mistake. Thank you so much for answering my question.

サインインしてコメントする。

 採用された回答

madhan ravi
madhan ravi 2019 年 4 月 25 日

1 投票

n=10;
S=cell(n,1);
for k = 1:n
S{k}=sprintf('./DataBase/%d/(%d).png',[k;k]);
... some operation
end

1 件のコメント

Elahe Karimi
Elahe Karimi 2019 年 4 月 25 日
Thank you so much for answering my question.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Structures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by