How to extract data from a cell array?
106 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Paolo Ottonelli
el 6 de En. de 2020
Editada: Paolo Ottonelli
el 6 de En. de 2020
Hello, it's the first time that i use arrays and I have a series of 3x1 cell arrays, each of them has 3 cells vith a differet numbers of numerical data. I want to use for loop or while loop in order to ectract the three cells and convert them into different 3 vectors:
C={[2.24;2.28;2.31], [0.99;1.44;1.44;1.44;1.44;2.12;2.25;2.48;3.61], [1.86;1.89;1.89;1.89;1.89;1.89;1.89]};
for j=1:length(C)
x(j)=C{j};
end
at the end I should have:
x1=[2.24;2.28;2.31]
x2=[0.99;1.44;1.44;1.44;1.44;2.12;2.25;2.48;3.61]
x3= [1.86;1.89;1.89;1.89;1.89;1.89;1.89]
1 comentario
Stephen23
el 6 de En. de 2020
"..at the end I need to have: x1... x2...x3"
Is there a particular reason why you cannot just use indexing to access your data?
Using numbered variables is certainly possible, but it will force you into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:
Indexing is simple, neat, easy to debug, and very effiicent. Unlike what you are trying to do.
Respuesta aceptada
KSSV
el 6 de En. de 2020
Already you have the cells in your desired way.
You can access them using C{1} , C{2}, C{3} .
You need to store them again into X1, X2, X3.
3 comentarios
Guillaume
el 6 de En. de 2020
"but i need to convert my array"
Why? As Stephen pointed out in his comment to your question, this will complicate your code for no useful benefit as far as we can tell. So please explain this need.
Why can't you write C{1} wherever you were going to write X1?
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!