Printing cell array with skipping a value

1 回表示 (過去 30 日間)
Nazar Adamchuk
Nazar Adamchuk 2021 年 10 月 14 日
編集済み: Dave B 2021 年 10 月 14 日
I have following code:
fileID = fopen('output.txt','w');
fprintf(fileID, '%s %g ', matComp{:});
fclose(fileID);
which gives
Fe 92.44 C 3.61 Si 2.81 Mn 0.23 P 0.014 S 0.009 Ni 0.88 Mg 0.041
Now I want to change the code so I get (no number after "Fe"):
Fe C 3.61 Si 2.81 Mn 0.23 P 0.014 S 0.009 Ni 0.88 Mg 0.041
Do you know how to do it?

採用された回答

Dave B
Dave B 2021 年 10 月 14 日
編集済み: Dave B 2021 年 10 月 14 日
If you want to get rid of just the one value, how about setting it to empty inside of matComp. Note that you'll end up with one extra space...
I'll use sprintf to display what you're putting in your file:
load('matlab.mat')
sprintf('%s %g ', matComp{:})
ans = 'Fe 92.44 C 3.61 Si 2.81 Mn 0.23 P 0.014 S 0.009 Ni 0.88 Mg 0.041 '
matComp{2,1}=[];
sprintf('%s %g ', matComp{:})
ans = 'Fe C 3.61 Si 2.81 Mn 0.23 P 0.014 S 0.009 Ni 0.88 Mg 0.041 '

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by