Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How do I convert a grid 'surface' variable to distinct X, Y and Z variables?

1 vue (au cours des 30 derniers jours)
Matthew Harris
Matthew Harris le 7 Fév 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have a large output from an analysis of mine that is a 1001x89 double. The first row is the Y axis, and the first column is the X axis. The other values are the Z 'surface' values that populate the grid. Here's a simplified example:
nan 500 497 494 491 488 ...
240 0.01 0.01 0.01 0.01 0.01 ...
241 0.01 0.01 0.01 0.02 0.02 ...
242 0.01 0.01 0.02 0.02 0.02 ...
243 0.02 0.02 0.02 0.02 0.03 ...
244 0.03 0.03 0.03 0.03 0.04 ...
... ... ... ... ... ... ...
I'm after a loop that, for a given Z value in the grid (i.e. not anything in [1,:] or [:,1]), assigns that value to a new variable whilst also assigning the first value in the corresponding row and column to distinct variables as well.
Any help will be greatly appreciated.

Réponses (1)

Rik
Rik le 7 Fév 2019
If you restructure your data you can use tools like find, ismember, and ismembertol. That way you can use logical indexing to select only the data you need.
data=[NaN 500 497 494 491 488
240 0.01 0.01 0.01 0.01 0.01
241 0.01 0.01 0.01 0.02 0.02
242 0.01 0.01 0.02 0.02 0.02
243 0.02 0.02 0.02 0.02 0.03
244 0.03 0.03 0.03 0.03 0.04 ];
[X,Y]=ndgrid(data(2:end,1),data(1,2:end));
Z=data(2:end,2:end);

Community Treasure Hunt

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

Start Hunting!

Translated by