Hi,
I have struct with 1801 X 921 elemants. I want to plot certain fields without the first row
so for example, if I use the following,
plot ([s.a(2,:)], [s.b(2,:)]);
it is giving error
can you please help me on this. Thanks.

12 Kommentare

madhan ravi
madhan ravi am 9 Jan. 2019
upload your struct as .mat file , post the complete error message
KSSV
KSSV am 9 Jan. 2019
YOu should post the error.
KSSV
KSSV am 9 Jan. 2019
dpreuben commented:
The error is as follows:
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
But I see brackets are properly balanced.
x = s.a(2,:) ;
y = s.b(2,:) ;
what does
whos x y
display?
Stephen23
Stephen23 am 9 Jan. 2019
dpreuben's "Answer" moved here:
Once I typed
x = s.a(2,:) ;
error is displayed as below:
Expected one output from a curly brace or dot indexing expression, but there were 1801 results.
Stephen23
Stephen23 am 9 Jan. 2019
Bearbeitet: Stephen23 am 9 Jan. 2019
@dpreuben: read these to know why your code does not work:
What size are the fields a and b? How do you want to join the multiple field values together: horizontally (as your code would seem to indicate)?
@KSSV: given that s is non-scalar (as stated in the question), what do you expect these to do?:
s.a(2,:)
s.b(2,:)
Did you try them with a non-scalar structure?
dpreuben
dpreuben am 10 Jan. 2019
Hi Stephen, Thanks a lot for the resources you shared. They are helping me a lot. the s.a and s.b are both 1801 X1
I would like to plot s.a Vs s.b (X Vs Y)
Stephen23
Stephen23 am 10 Jan. 2019
@dpreuben: according to your description so far:
  1. structure s has size 1801*921
  2. each of the fields of that structure a and b has size 1801*1.
That seems a bit of an unusual coincidence to me: why does the structure happen to have exactly the same number of rows as all of its fields do?
Please show us the output of these commands:
size(s)
size(s(1).a)
size(s(1).b)
Stephen23
Stephen23 am 10 Jan. 2019
dpreuben's "Answer" moved here:
Hi Michael:
size (s) - ans: 1801 1
size (s(1).a) - ans: 1 1
size (s(1).b) - ans: 1 4
Now I am confused :(
madhan ravi
madhan ravi am 10 Jan. 2019
Who‘s Micheal?
Stephen23
Stephen23 am 10 Jan. 2019
Bearbeitet: Stephen23 am 10 Jan. 2019
The structure has size 1801*1, and its first element's a and b fields contain arrays with sizes 1*1 and 1*4 respectively. This means that both a and b have exactly one row, so what you ask in your question does not make sense: "I want to plot certain fields without the first row". What data do you want to get from non-existent rows?
Possibly other elements of s have fields with more than one row, but you would still need to explain if single rows (like the ones you have shown) should be ignored, or throw an error, or whatever you need. Please upload the structure in a .mat file by clicking the paperclip button.
dpreuben
dpreuben am 22 Jan. 2019
Bearbeitet: dpreuben am 22 Jan. 2019
Please find the matlfile attached. My aim is to plot s.a vs s.b

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephen23
Stephen23 am 22 Jan. 2019

1 Stimme

3 Kommentare

dpreuben
dpreuben am 22 Jan. 2019
Hi Stephen,
Thanks a lot. This answers my question.
But I am still curious why Size (s(1).a) is 1 X1 and Size (s(1).b) is 1 X 4
Can you please explain becuase looking at the data both s.a and s.b are 2 columns.
Thanks.
Stephen23
Stephen23 am 22 Jan. 2019
Bearbeitet: Stephen23 am 22 Jan. 2019
Whoever created that structure placed some character vectors (apparently the units of the numeric data) in the first element of s, i.e.:
  • s(1).a contains the char vector 's' (which has size 1x1).
  • s(1).b contains the char vector 'kg/h' (which has size 1x4).
All the rest of the data are numeric scalar. You could have easily found this out yourself, by looking at the data itself in the Variable Viewer. Or you could have looked at my answer, where I use those character vectors as the axes labels.
This is certainly an innovative way to store that data, but not a very efficient or clear (the numeric data would be efficiently stored in numeric arrays, and the units in their own fields).
Please remember to accept my answer!
dpreuben
dpreuben am 22 Jan. 2019
Thanks a lot Stephen.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Gefragt:

am 9 Jan. 2019

Kommentiert:

am 22 Jan. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by