Reputation: 21
I have a struct that looks something like this:
data.index
data.x
data.y
It has anywhere from 1 to 100 elements that I can access with data(Window_Size).y
(or whatever). What I want to do is compare all x values and all y values, independently, to get the maxX, maxY, minX, and minY.
I tried something like this
MaxX = max(data(:).x);
but that doesn't seem to work. Any help would be appreciated; I have absolutely zero experience with Matlab beyond the past few hours trying to figure this out.
Upvotes: 2
Views: 448
Reputation: 60574
You’re almost there! Try this:
MaxX = max([data.x]);
data.x
is a comma-separated list of all values in the x
field. The []
concatenates them into a row array, sort of the same as [data(1).x, data(2).x, ...]
.
Upvotes: 4