Data representation of Integer values in .mat file
Show older comments
Hello ,
I have attached mat file which has one table with x,y,polylinetype ..etc
In Table "y" , i could see the row number 9 has whole number i.e instead of 3787 on 3.7870e+3 but rest of the data are represented as 1.3e+3
how can i represent all the data in syn form i.e 1.23e+3 ?
Accepted Answer
More Answers (1)
Robin Kirsch
on 12 Jun 2020
Use the format operator found here
>> format shortEng
>> 3787
ans =
3.7870e+003
7 Comments
SatyaPrakash Gupta
on 12 Jun 2020
Edited: SatyaPrakash Gupta
on 12 Jun 2020
Walter Roberson
on 12 Jun 2020
How can i generatlize this for complete set of data for the attached matfile i have provided before ?
You cannot do that easily. Your struct includes multiple data types, including graphic objects, and you have limited control over how matlab displays non-numeric fields.
SatyaPrakash Gupta
on 12 Jun 2020
Walter Roberson
on 12 Jun 2020
I do not think I understand what you are asking for?
matfile =
struct with fields:
x: [71×1 single]
y: [71×1 single]
PolylineType: {'Guardrail(motorway)'}
subLabelType: {'Mono'}
Color: ' ([85 96 112]./255)'
PolylineNumber: 10
MATLAB's default display of struct never displays the numeric content of a numeric field that has more than one row.
MATLAB's default display of struct that has a numeric row, examines to see how wide the current screen is, and uses the current "format" to figure out how many items fit across the display, and displays at most that many, using the [1 x WHATEVER] notation if there are more items. For example
>> format shortg
>> foo
foo =
struct with fields:
y: [0.24914 0.37512 0.41353 0.16518 0.94197]
>> format long g
>> foo
foo =
struct with fields:
y: [1×5 double]
MATLAB does not provide any way to customize the display of struct fields. It is not possible to tell MATLAB to use %.2e format for example; the only control is the format command.
If you were displaying the content of matfile.y by itself then the best way would be to use fprintf() with whatever format you want, such as the fprintf('%.2e\n',matfile.y) that I showed.
SatyaPrakash Gupta
on 15 Jun 2020
Edited: SatyaPrakash Gupta
on 15 Jun 2020
Walter Roberson
on 15 Jun 2020
You need %.16e to avoid data loss
SatyaPrakash Gupta
on 15 Jun 2020
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!