필터 지우기
필터 지우기

convert 1x20 double struct into a vector containing 20 values

조회 수: 5 (최근 30일)
Kick Greven
Kick Greven 2023년 2월 1일
댓글: Jan 2023년 2월 1일
I have a struct which is '1x20 double'
When I plot this, I get these 20 y-values plotted from x=1 to x=20
However, I need to be able to plot all of these values on the same x coordinate.
Nothing I do works because it is in a struct.
struct2table/struct2cell do not work.
  댓글 수: 3
Kick Greven
Kick Greven 2023년 2월 1일
Well It's a 1x307 struct with 10 fields that I extracted 20 values from into a new variable via indexing. I guess this variable is not a struct then? The code generating the struct is 400+ lines long so I decided not to share. I think that the variable wasn't a struct after all, but I got very confused about the way that it didn't look like a vector or matrix so I didn't know what to do.
Jan
Jan 2023년 2월 1일
@Kick Greven: You can simply check, what the type is using the class() command.
"a 1x307 struct with 10 fields that I extracted 20 values from into a new variable via indexing." - Please note, that you might know, what this means, but a reader can have a faint idea aboud the corresponding procedure only. This is the hard part of asking question: considering that the readers know as much as a rubber duck about the problem while you hope, that they can solve it. :-)

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

답변 (1개)

Jan
Jan 2023년 2월 1일
With wild guessing:
S.y = rand(1, 20); % Is this equivalent to your struct?
plot(S.y); % Is this the way your get a plot?
% And you want this:
x = 2;
figure;
plot(x, S.y, 'o')
Remember, that plot(x, S.y) without specifying the marker will not show anything, because lines appear only, if their length is greater than 0, what is not true for single points.
  댓글 수: 1
Kick Greven
Kick Greven 2023년 2월 1일
This actually looks like it might be a perfect solution. Thank you so much. I have been searching for the wrong solution for about an hour now. Thanks a lot.

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

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by