How to extract values from a field of a stucture?

조회 수: 2 (최근 30일)
Kelto7
Kelto7 2019년 9월 26일
댓글: Kelto7 2019년 9월 26일
Hi everyone, I state that I'm a beginner in the use of Matlab, so I guess that what I'm asking could be solved quite easily, but I have been reading and trying a lot of different ways and still, I have no solutions. I have a structure ("Dati"), which is generated by an external software that works on a geographic grid. This grid has 196 cells in the X direction, and 337 in the Y direction; On this grid 244 different scenarios have been launched.
By writing "A=extractfield(Dati,'Val') I get, of course, the list of all the data inside the structure, and by "plot(extractfield(Dati,'X'),extractfield(Dati,'Y'))" I can represent the grid; but what I would like is to get the chance to represent in a plot the grid with all the different scenarios (244), and be able to handle the value of the third variable (energy per transport) in order to later calculate an average. Can someone help me?

채택된 답변

Fabio Freschi
Fabio Freschi 2019년 9월 26일
I don't have the data so I cannot test it. Try
% select the Scenario
iScenario = 1;
% plot
surf(Dati.X,Dati.Y,Dati.Val(iScenario,:,:));
Note that the field Val has different dimensions from X and Y, so the previous code doesn't work. But maybe you have more insight on the original data
  댓글 수: 5
Fabio Freschi
Fabio Freschi 2019년 9월 26일
I arbitrarily remove the first row and column of X and Y to match the dimensions of Val. Maybe you know why X and Y have an additional row/col
figure;
s = surf(data.X(2:end,2:end),data.Y(2:end,2:end),squeeze(data.Val(1,:,:)));
s.EdgeColor = 'none';
light
Kelto7
Kelto7 2019년 9월 26일
Dear Fabio, Thank you very much for your help. Actually I must check the problem of the additional row/colum, because the plot has no sense, but it's what I was looking for! Do you think that could be possible to then organize X, Y and Z in three columns and 65520 rows (195x336), like
X Y Z
1 449604 5841736 1393.9
2 449639.531 5841771 1344.9
... .............. .............. ..............
65520 ............ .............. ..............

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by