Z must be a matrix, not scalar or vector - SURF

Hello,
Attached is a screenshot of my code and a table I recreated in excel. Just pretend it is in MATLAB. Unfortunaltly, because this is for work, I cannot share actual screenshots, so I made a simplified mock up to show you.
'b' is the variable name I call from.
'c' is just what I call the length of b, which is 12.
The table is a 1x12 structure with 12 fields. For my example, I only show 1 to 5, but you ge the idea to show you where I get the error 'Z must be a matrix, not scalar or vector.'
I appreciate any help/advice. Thanks!
.....

 채택된 답변

Sindar
Sindar 2020년 10월 27일

0 개 추천

struct array is a terrible way to store this data. Does this do it?
tbl = struct2table(b);
surf(tbl.temperature,tbl.humidity,tbl.frequency)
% no loop

댓글 수: 4

Sindar
Sindar 2020년 10월 27일
The issue with your code is that you are trying to build a surface line by line, but that doesn't make sense to Matlab
Sindar
Sindar 2020년 10월 27일
편집: Sindar 2020년 10월 27일
What were you expecting? The x and y values seem to be the same for every row
For homogenous data, tables are so much better. I'm still kinda bitter that I learned Matlab on a (old-at-the-time) version prior to tables, and coded everything up badly with struct arrays, before learning about tables.
Sclay748
Sclay748 2020년 10월 27일
oh i guess that makes sense. I just was looking for the typical surface looking graph, but you made me realize that haha
Sclay748
Sclay748 2020년 10월 27일
thank you!

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2020a

질문:

2020년 10월 27일

댓글:

2020년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by