How show variable number of cell's array in a message box?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everyone,
I want a cell, which includes every time (depend on calculation) different number of array. It means, depend on calculation the number of arrays could be 2 or 3 etc. Now I want to show the content of this cell in a message box. I have written the following:
%X_AP_Name is the cell with variable number of arrays
msgbox(sprintf('Please insert *.txt-data of %s in folder sample',X_AP_Name{:}))
but the text before and after arrays of cell is repeated according to number of arrays. If for example Size(X_AP_Name)=2, it result in following text: "Please insert *.txt-data of A in folder samplePlease insert *.txt-data of B in folder sample"
But i want to have "Please insert *.txt-data of A and B in folder sample"
what should I do?!
0 件のコメント
採用された回答
Guillaume
2015 年 3 月 5 日
msgbox(sprintf('Please insert *.txt-data of %s in folder sample', strjoin(AP_Name, ' and ')));
You could make something a bit more advanced to make the sentence look nicer, like:
function filestring = buildfilestring(filenames)
%filenames: a cell array of string
if numel(filenames) > 2
filestring = sprintf('%s and %s', strjoin(filenames(1:end-1), ', '), filenames{end});
else
filestring = strjoin(filenames, ' and ');
end
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!