Plotting data from struct

조회 수: 15 (최근 30일)
Leandro Seguro
Leandro Seguro 2021년 1월 1일
편집: dpb 2021년 1월 1일
Hi all,
I am trying to plot the data from the ''Cost'' column located in the pop struct which I have attached, where each cell in that column contains an x and y value for what I need to plot.
I've been trying to extract the data but I can't seem to figure it out. Any help would be appreciated!
Many thanks in advance.

채택된 답변

dpb
dpb 2021년 1월 1일
편집: dpb 2021년 1월 1일
Couple ways of many...
XY=reshape([pop.Cost],2,[]).';
plot(XY(:,1),XY(:,2))
or
tpop=struct2table(pop);
plot(tpop.Cost(:,1),tpop.Cost(:,2))
You've got to get the data into a more amenable form than an array of struct to operate on all at once; this form is good if can apply the same function to each element independently; together, "not so much".
  댓글 수: 1
Leandro Seguro
Leandro Seguro 2021년 1월 1일
Cheers for that, worked a treat!

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

추가 답변 (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