How to access elements in a convoluted cell array.

2 ビュー (過去 30 日間)
jungdnb
jungdnb 2016 年 12 月 23 日
コメント済み: Image Analyst 2016 年 12 月 27 日
Hello and happy holidays to everyone.
I have an convoluted cell array IZ, with the size 1x12, that looks like this
IZ =
Columns 1 through 7
'4 8 12 16' '15 26 30 34' '4 8 12 16' '4 8 12 16' '4 15 17 21' '3 7 9 28' '3 7 9 28'
Columns 8 through 12
'3 7 9 28' '3 7 9 28' '3 14 16 35' '3 14 16 35' '3 9 11 30'
I know, I can access the single columns by typing IZ{x}, where x is the column index. But how can I access for example say third element of first column? Many thanks and greetings.

採用された回答

Jan
Jan 2016 年 12 月 26 日
What is "the 3rd element of the 1st column"? Do you mean the 12 as a number?
IZ = {'4 8 12 16', '15 26 30 34', '4 8 12 16'} % The rest does not matter here
FirstCol = IZ{1};
Number = sscanf(FirstCol, '%f');
Value = Number(3)
Or is the "3rd element" the 3rd character of the string? Please clarify this.
  1 件のコメント
jungdnb
jungdnb 2016 年 12 月 27 日
編集済み: jungdnb 2016 年 12 月 27 日
I mean the number 12 as a number. I don't understand the line FirstCol = IZ{1}, is 1 the index of first column? I try your suggestion like this:
for idx=1:length(IZ)
Col = IZ{idx};
Number = sscanf(Col, '%f');
Value = Number(3)
end
Thank you, it works perfect.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 12 月 26 日
I don't know what convoluted means. To me it means very complicated but some people use it to mean "convolved" like the result of a convolution operation. Anyway.....
Try this:
IZ = {'4 8 12 16',...
'15 26 30 34',...
'4 8 12 16',...
'4 8 12 16',...
'4 15 17 21',...
'3 7 9 28',...
'3 7 9 28',...
'3 7 9 28',...
'3 7 9 28',...
'3 14 16 35',...
'3 14 16 35',...
'3 9 11 30'}
% IZ is a row vector of cells with 12 columns - "1×12 cell array"
% First get the first cell contents.
% First column is a string with 4 numbers and spaces in it.
col1String = IZ{1} % Extract contents into a string '4 8 12 16'
% Get third element of the first column.
% The third element of that string is a space.
element3 = col1String(3) % This will be a space.
  2 件のコメント
jungdnb
jungdnb 2016 年 12 月 27 日
Thx, this is also useful for me, but for antoher problem. I meant with "third element" the number 12, or with ongoing number of columns, numbers 30, 17, 9, 16, etc.
Image Analyst
Image Analyst 2016 年 12 月 27 日
I think the FAQ might also help you understand cell arrays: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F

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

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by