Values are getting converted to double automatically.
9 次查看(过去 30 天)
显示 更早的评论
I have to load files having numbers in the filename. For example: CRH_0.5d_15.mat, 0.5d_15.mat. Following is the code I am using to access my files. The problem I am facing is, the values in the array are getting read as double type i.e. instead of b=0.5, it is taking b=0.5000. I tried using format short, but to no avail. Could someone help me with this? Thank you.
ab=[0.5,0.75,1,1.25,1.5,2] Ln= length(ab) for l=1:1:Ln b= ab(l) a= load('CRH_',num2str(b),'d_15'); end
4 个评论
Stephen23
2023-9-29
Changing the format controls how numeric values are displayed in the command window, it has nothing to do with functions like num2str. If you want to have more control over the format whilst converting to text then use sprintf or similar.
回答(1 个)
James Tursa
2023-9-29
Here is what I get just displaying the character string. I inserted brackets [ ] for concatenation:
ab=[0.5,0.75,1,1.25,1.5,2];
Ln= length(ab);
for l=1:1:Ln
b= ab(l);
disp(['CRH_',num2str(b),'d_15']);
end
Maybe you just need the brackets [ ].
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!