Tips: format long - script error?

error
formatlong
substring

#1

It is reasonable to use the format command to increase the number of digits of precision to 16. For example,

format long;
?real(getdata("FDE::data::mode1","neff"));
result: 
1.391005254977223 

However, in some situations, it might hinder you from proceeding because of the high precision.

format long;
a=1;
neff = real(getdata("FDE::data::mode"+num2str(a),"neff"));
Error: prompt line 3: in getdata, the d-card named FDE::data::mode1.000000000000000 was not found.
  Try the command '?getdata;' to see which d-cards are available.

An error is returned because a=1.000000000000000. It always returns the number with 16 digits of precision when format long is used. And obviously, there is nothing named “mode1.000000000000000”.

One other way to do this is to make use of the substring command to “filter” out the zeros before using getdata

format long;
a=1;
a=num2str(a);
a=substring(a,1,1);
?neff = real(getdata("FDE::data::mode"+a,"neff"));

This can be useful if you would like to loop over a to get the neff of multiple modes in FDE.


How to calculate the mode effective index precisely?
팁: format long - 스크립트 에러?