Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

1 回表示 (過去 30 日間)
Matthew Harris
Matthew Harris 2019 年 2 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.

回答 (1 件)

Rik
Rik 2019 年 2 月 7 日
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