MATLAB Answers

0

Extracting Data from Cells

Devrim Tugberk さんによって質問されました 2019 年 7 月 19 日
最新アクティビティ madhan ravi
さんによって コメントされました 2019 年 7 月 19 日
Dear Matlab users,
I am facing some trouble extracting data from a cell. I attached the a screenshots showing what my cell looks like (cells within a cell). Each cell in the "big" cell has xyz data and i would like to extract each column representing the respective coordinates as column vectors.
My explanation might have been confusing so i will try summarize: Extract the "minor" cells from the main cell, extract the xyz from each minor cell as column vectors.
Thank you for the help
Capture.JPG
Capture_1.JPG

  3 件のコメント

Guillaume
2019 年 7 月 19 日
What does extract mean? What do you want to do afterward?
Adam Danz
2019 年 7 月 19 日
I interpreted it as an indexing question.
Devrim Tugberk 2019 年 7 月 19 日
My goal was the "extract" the xyz coordinates as column vectors and plot them using scatter3()

サインイン to comment.

3 件の回答

madhan ravi
回答者: madhan ravi
2019 年 7 月 19 日
編集済み: madhan ravi
2019 年 7 月 19 日
 採用された回答

vv=cellfun(@(x) x(:,1:3),cross_sections,'un',0); % assuming the first three columns in each cell represents x,y & z
v=cat(1,vv{:}); % gathering x,y, & z of each cell into one matrix
scatter3(v(:,1),v(:,2),v(:,3))
% x -^ ^- y ^- z

  7 件のコメント

Devrim Tugberk 2019 年 7 月 19 日
Perfect! Thank you all very much
Devrim Tugberk 2019 年 7 月 19 日
One last tiny tweak, is there a way I could supress the scatter3 function so it doesnt spit out 138 figures? Maybe just give me 138 tables or vectors or something which i can refer back to and plot the desired one only?
madhan ravi
2019 年 7 月 19 日
Then for instance:
scatter3(vv{2}(:,1),vv{2}(:,2),vv{2}(:,3))

サインイン to comment.


Adam Danz
回答者: Adam Danz
2019 年 7 月 19 日
編集済み: Adam Danz
2019 年 7 月 19 日

I think this is the format of your data:
C = {rand(20,4),rand(15,4),rand(22,4)};
Extract the first 3 columns of cell 2
C{2}(:,1:3)
Extract column 2 of cell 3
C{3}(:,2)
Extract the entire matrix from cell 1
C{1}
Extract the entire matrix from cell 1 but reorganize it into a single column
C{1}(:)

  1 件のコメント

Adam Danz
2019 年 7 月 19 日
"My goal was the "extract" the xyz coordinates as column vectors and plot them using scatter3()"; " I need to have 3 column vectors for each cell"
@ Devrim Check out the 2nd block of code in my answer. It does what you're describing. If you want to perform that block on all cells,
c3 = cellfun(@(x)x(:,1:3), C, 'UniformOutput', false)

サインイン to comment.


Guillaume
回答者: Guillaume
2019 年 7 月 19 日
編集済み: Guillaume
2019 年 7 月 19 日

If you want to create a scatter3 plot using the coordinates from all the cells of Cross_sections, this is how I'd go about it:
allsections = vertcat(Cross_sections{:});
scatter3(allsections(:, 1), allsections(:, 2), allsections(:, 3));

  2 件のコメント

madhan ravi
2019 年 7 月 19 日
Probably you meant:
allsections = vertcat(Cross_sections{:});
Guillaume
2019 年 7 月 19 日
Indeed! Otherwise, the operation does nothing.

サインイン to comment.



Translated by