필터 지우기
필터 지우기

Plotting a field from a struct inside a struct

조회 수: 2 (최근 30일)
DP
DP 2020년 8월 5일
댓글: DP 2020년 8월 6일
Hey everyone,
I have this 1x543 struct called BB, inside BB is one field called 'blobs' that contains 543 unqiue structs of various sizes (some empty!). Inside each of these 543 struct is one common field called 'Area', I want to plot Area per total number of fields (543).
I created a few pieces of code to extract data, but I keep ending up plotting the Area values vs the number of areas inside its own struct.
Any ideas? Thank you!

채택된 답변

Sudheer Bhimireddy
Sudheer Bhimireddy 2020년 8월 6일
Try this:
nBlobs = numel(BB);
h = figure;
clf;
hold on;
for i = 1:nBlobs
x = i;
temp = BB(i).blob;
temp_size = numel(temp);
if temp_size == 0
% This is if you have 0x1 in a BB(i).blob
% If you dont want to plot 0, simply remove below line
plot(x,0,'ko');
else
for j = 1:temp_size
y=temp(j).Area
plot(x,y,'ko');
end
end
end
Hope this helps.
  댓글 수: 1
DP
DP 2020년 8월 6일
Ah, this makes a lot of sense. Thank you!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by