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 comentarios

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

Iniciar sesión para comentar.

 Respuesta aceptada

madhan ravi
madhan ravi el 19 de Jul. de 2019
Editada: madhan ravi el 19 de Jul. de 2019

0 votos

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 comentarios

Devrim Tugberk
Devrim Tugberk el 19 de Jul. de 2019
This puts me back to where i started from, maybe my problem wasn't stated properly. At the end, I need to have 3 column vectors for each cell (which represent the xyz respectively). In other words 3 times 138 column vectors with each vector being a coordinate (either x,y or z)
madhan ravi
madhan ravi el 19 de Jul. de 2019
vv would contain the vectors as per your requirement
Devrim Tugberk
Devrim Tugberk el 19 de Jul. de 2019
Okay this script got me the closest so far but my problem with it is that it's plotting ALL of the vectors whereas I want the plot of one single vector xyz to generate the plot of a single cell rather than all of them at once. The point is to be able to analyze each plot individually. I'm sorry i am learning as i go.
madhan ravi
madhan ravi el 19 de Jul. de 2019
for k = 1:numel(vv)
figure(k)
scatter3(vv{k}(:,1),vv{k}(:,2),vv{k}(:,3))
end
Devrim Tugberk
Devrim Tugberk el 19 de Jul. de 2019
Perfect! Thank you all very much
Devrim Tugberk
Devrim Tugberk el 19 de Jul. de 2019
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
madhan ravi el 19 de Jul. de 2019
Then for instance:
scatter3(vv{2}(:,1),vv{2}(:,2),vv{2}(:,3))

Iniciar sesión para comentar.

Más respuestas (2)

Adam Danz
Adam Danz el 19 de Jul. de 2019
Editada: Adam Danz el 19 de Jul. de 2019

1 voto

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 comentario

Adam Danz
Adam Danz el 19 de Jul. de 2019
Editada: Adam Danz el 19 de Jul. de 2019
"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)

Iniciar sesión para comentar.

Guillaume
Guillaume el 19 de Jul. de 2019
Editada: Guillaume el 19 de Jul. de 2019

0 votos

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));

3 comentarios

madhan ravi
madhan ravi el 19 de Jul. de 2019
Probably you meant:
allsections = vertcat(Cross_sections{:});
Guillaume
Guillaume el 19 de Jul. de 2019
Indeed! Otherwise, the operation does nothing.
Franklin
Franklin el 15 de Abr. de 2022
Editada: Franklin el 15 de Abr. de 2022
Hello All;
I have a 70x1 cell data called info. Inside info is the 1x1 struct, each with 2 variables A and B. index 1.A and 1.B have a size(827x1) while all others 2.A or 2.B...70 are 1348x1.
Am able to extract some portions of "info" e.g. Y_1...Y_5 which I would use for my Y axis on the plot
Q1. How do I plot test1 (Y axis) against X_2(X Axis) without array errors e.g. Arrays have incompatible sizes for this operation.
Q2. How do I get Yall using a Loop or any faster method
Code:
Y_2 = info{2}(:,1).B; % Get Cell 2B data i.e. 1348x1 double
Y_3 = info{3}(:,1).B; % Get Cell 3B data i.e. 1348x1 double
Y_4 = info{4}(:,1).B; % Get Cell 4B data i.e. 1348x1 double
Y_5 = info{5}(:,1).B; % Get Cell 5B data i.e. 1348x1 double
X_1 = info{1}(:,1).A; % Get Cell 1A data i.e. 827x1 double
X_2 = info{5}(:,1).A; % Get Cell 5A data i.e. 1348x1 double
Yall = Y_2...Y_70; % Get all Y values using a loop
test1 = Yall./X_1;
figure(2)
plot(X_2,test1);hold on;
figure(3)
plot(X_1,test1);hold on;

Iniciar sesión para comentar.

Categorías

Preguntada:

el 19 de Jul. de 2019

Editada:

el 15 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by