A problem about using %f

1 回表示 (過去 30 日間)
Mustafa Uysal
Mustafa Uysal 2019 年 5 月 25 日
編集済み: per isakson 2019 年 5 月 25 日
hİ, i am beginner with matlab
i'm trying to show just first 3 digits of these numbers.
l.png
For example 150 for first one and 122 for second one. How can i do this?
Here is my code of that part
handles.popupmenu3.String{end+1} = sprintf('l(%d)= %.1f',i,l(i));

採用された回答

per isakson
per isakson 2019 年 5 月 25 日
編集済み: per isakson 2019 年 5 月 25 日
Try this
%%
K = randi( [1e9,9e9], 1,9 ); % sample data
%%
cac = arrayfun( @(x) num2str(x), K, 'uni',false );
%%
str = string.empty; % or str = cell(1,0);
for ii = 1 : 9
str{end+1} = sprintf( 'l(%d)= %s', ii, cac{ii}(1:3) );
end
str([1,7])
outputs
ans =
1×2 string array
"l(1)= 655" "l(7)= 712"
>>

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by