Filter löschen
Filter löschen

how to access elements of a vector inside a cell array

13 Ansichten (letzte 30 Tage)
Chiara Scarpellini
Chiara Scarpellini am 11 Aug. 2021
Bearbeitet: Dave B am 11 Aug. 2021
I need to access with a for loop all the elements of SimulatedPoints but I struggle with finding the notation. This is what I did but it returns the entire vector of the cell.
for j=1:length(SimulatedPoints.Codes{idxRow,:})
end
  1 Kommentar
Stephen23
Stephen23 am 11 Aug. 2021
Bearbeitet: Stephen23 am 11 Aug. 2021
"how to access elements of a vector inside a cell array"
What cell array?
Your screenshot shows a 2785x3 table containing strings and numeric values. I do not see any cell array.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Dave B
Dave B am 11 Aug. 2021
The length part should return the entire contents of the cell, so your code looks fine to me. Inside the loop you'd refer to the individual elements of the cell:
name=["a";"b"];
codes=[{rand(3,1);rand(5,1)}];
t=table(name,codes)
t = 2×2 table
name codes ____ ____________ "a" {3×1 double} "b" {5×1 double}
row = 2;
for i = 1:length(t.codes{row})
disp(t.codes{row}(i))
end
0.3208 0.7280 0.7743 0.9703 0.6213
  2 Kommentare
Stephen23
Stephen23 am 11 Aug. 2021
"The length part should return the entire contents of the cell"
What cell array?
Is your answer finally an official TMW announcement that cell arrays andf tables really are one and the same?
Dave B
Dave B am 11 Aug. 2021
Bearbeitet: Dave B am 11 Aug. 2021
@Stephen Cobeldick - My answer is an offical TMW announcement of anything, I just jump on answers sometimes to help out when I'm not too busy. But personally, I certainly don't think of tables and cell arrays as the same, they seem quite different in many regards (although you can convert between them quite easily). I didn't mean to jump into something controversial.
In this example there's clearly a cell, you can see it in the disp, and isa(t.codes(2),'cell') returns true. So t.codes{row} returns the contents of the cell t.codes(row), right?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by