How to access nested cell data?
1 次查看(过去 30 天)
显示 更早的评论
I am attaching the file which contains the coordinates of a polygon. I want to split the data given in the attached file into x and y variables. For example:
x=[1,1,2,2,1,NaN,4,4,5,5,4,NaN,6,6,7] and
y=[1,1,2,2,1,NaN,4,4,5,5,4,NaN,6,6,7]
How can i split my data into this format. Please do answer my question. Thank you
0 个评论
采纳的回答
Guillaume
2015-4-23
编辑:Guillaume
2015-4-23
it's very unclear what you're asking particularly as there's no value in your demo matrix that belongs to the set [1,1,2,2,1,NaN,4,4,5,5,4,NaN,6,6,7].
In view that your cell array contains exclusively, N x 2 matrices, I'll assume that you just want to concatenate the whole lot. Use vertcat together with expension of cell array into comma separated lists:
load('trialdataofcoordinates.mat');
coords = vertcat(mycoordinates{:});
x = coords(:, 1)
y = coords(:, 2)
3 个评论
Guillaume
2015-4-23
The simplest way is to add a row of 1x2 matrices of NaN to your cell array. The reshaping into a single column (with the : operation) will automatically place the NaN matrix in between each other matrices:
load('trialdataofcoordinates.mat');
mycoordinates(2, :) = {[nan nan]};
coords = vertcat(mycoordinates{:});
x = coords(:, 1)
y = coords(:, 2)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!