Trouble displaying single value of a structured array

Within the Command Window, I've first loaded global coastline by
load('ocean_coast.mat')
The fields are 'area','Lat','Lon','BoundingBox','id' & 'level'. The array length is 179837.
When I try to look at just one value, for example, by fprintf('Lat %2f \n',ocean_coast(1).Lat), I get all of the latitudes. I've tried with 'disp' also.
I haven't tried the smaller data set of lake coast data yet.
What is it that I'm doing wrong? Do I need to filter by size?

댓글 수: 5

Please show the output of this command:
whos ocean_coast
Name Size Bytes Class Attributes
ocean_coast 179837x1 358202698 struct
Please show the output of these commands:
A = ocean_coast(1).Lat;
whos A
>> A = ocean_coast(1).Lat;
>> whos A
Name Size Bytes Class Attributes
A 1x1160927 9287416 double
That's a vector of many values. So if you only want to look at the first value, e.g.,
ocean_coast(1).Lat(1)

댓글을 달려면 로그인하십시오.

답변 (1개)

Sachin
Sachin 2023년 8월 4일
편집: Sachin 2023년 8월 4일
Hi Chandra,
I understand that you want to display single value of structured array.
A possible workaround be finding the size of the values of field “Lat”. Since you are getting all the “Lat” values so there may be multiple “Lat” values at that index.
You need to first find out the size of the field and try to access the data of that field.
You can try following MATLAB code to find size.
load('ocean_coast.mat');
length(ocean_coast(1).Lat);
disp(ocean_coast(1).Lat(1));
Thanks
Sachin

카테고리

도움말 센터File Exchange에서 Time Series Events에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

질문:

2023년 6월 22일

편집:

2023년 8월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by