필터 지우기
필터 지우기

For cycle over a struct array

조회 수: 3 (최근 30일)
Tiziano Bagnasco
Tiziano Bagnasco 2022년 5월 30일
댓글: Tiziano Bagnasco 2022년 5월 30일
Hello everyone,
I am considering a 1x1 struct array ( named hs) that contains 49 matrices ( 72x77) that represent the significant wave height in all the grid points of my domain. I would like to create a for cycle to plot how the significant wave height is changing during time/space. I know how to extract the matrices one by one from the struct array but it is time consuming and I would like to create a cycle ( with the pcolor command).
Xp (72x77) is the matrix that contains the x-coord of the grid points
Yp (72x77) is the matrix that contains the y-coord of the grid points
How can i write the for loop?
Thank you for your help.
  댓글 수: 2
Voss
Voss 2022년 5월 30일
"I know how to extract the matrices one by one from the struct array"
Can you show how you do this? I ask because the situation is a little confusing to me. For example, "a 1x1 struct array" is a scalar struct. If it "contains 49 matrices", does that mean the struct has 49 fields, with each field being one matrix? Probably seeing the code you have so far would help to answer those kinds of questions.
Tiziano Bagnasco
Tiziano Bagnasco 2022년 5월 30일
Thank you for your answer! This is the content of 1x1 struct array..
I can extract a matrix in this way : hs1=hs.Hsig_20000103_000000(:,:);
But I am not able to create a for cycle like this ( of course what I wrote below doesn't work.. it is just to show what I kind of want to obtain).
for i=1:49
pcolor( Xp,Yp,hs(i))
end

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

채택된 답변

KSSV
KSSV 2022년 5월 30일
s = struct2cell(hs) ;
N = length(s) ;
for i = 1:N
pcolor(XP,Yp,s{i})
drawnow
end

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by