Access specific values in cell aray

1 回表示 (過去 30 日間)
JKM1000
JKM1000 2015 年 8 月 11 日
コメント済み: Star Strider 2015 年 8 月 11 日
I have a cell array "Z" which I would ultimately like to plot certain values from.
Example code:
A = [1;2;3;4;5]
B = [11;12;13;14;15]
C = [111;112;113;114;115]
Z = {A,B,C}
%Now, what I want to do is return the first value of each column so that I see 1 11 111
%This is what I've tried that doesn't work:
Y = Z{1,1:3}(1,1)
%Thank you for your help

回答 (1 件)

Star Strider
Star Strider 2015 年 8 月 11 日
I can’t devise any way to vectorise what you want to do. The easiest would be:
M = cell2mat(Z);
Y = M(1,:);
  2 件のコメント
Image Analyst
Image Analyst 2015 年 8 月 11 日
What if the column vectors are not all the same length, like:
A = [1;2;3;4;5]
B = [11;12;13;14;15;16]
C = [111;112;113;114;115;116;117]
Z = {A,B,C}
JKM, is that even a possibility? If so, then how would you get the top row value of each column?
Star Strider
Star Strider 2015 年 8 月 11 日
@Image Analyst — I considered that, then remembered ‘... which I would ultimately like to plot certain values from.’ So they would likely have to have the same lengths, at least if they are all plotted against the same independent variable.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by