Cell2mat conversion

조회 수: 6 (최근 30일)
harjan
harjan 2012년 3월 7일
댓글: harjan 2013년 10월 5일
Hi, I have one cell with 256X10 string values...If I want to convert it to matrix of size 256X10(using cell2mat) it contains full of strings....I can't access the matrix elements like matrix(4,5)... How to convert the cell of strings to matrix....Please post your ideas...

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 3월 7일
C ={['QRSTUVWXYZ'
'[\]^_`abcd'
'efghijklmn'
'opqrstuvwx']}
out = C{1}(4,5)
ADD
on Harjan's comments
C ={['QRSTUVWXYZ'
'[\]^_`abcd'
'efghijklmn'
'opqrstuvwx']};
C = repmat(C,4,4)
out = C{1,2}(1,1:10)
  댓글 수: 2
harjan
harjan 2012년 3월 7일
But I need to store the 15th row of 10 values to a variable and access it how to possible if I use for loop,
for i=1:10
out = C{i,1:10}
end
then it shows error.....How to solve this...
Walter Roberson
Walter Roberson 2012년 3월 7일
out = C(i,1:10);
Then access out{1}, out{2}, and so on.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 3월 7일
When you say 256x10 do you mean 256 entries each of which is exactly 10 characters long? And you want to convert to a matrix so as to access the individual characters?
If so, then instead of using cell2mat() use char()
  댓글 수: 3
Walter Roberson
Walter Roberson 2012년 3월 7일
Looking at what you have said you want to do, I do not see any reason why you would want to convert the cell array to a matrix.
It appears to me that you just want to take portions of the cell array as a group. You would do that in the way I showed in Andrei's answer: C(i,1:10) would extract down to a 1 x 10 cell array, and you could then access the individual strings if you want to.
harjan
harjan 2012년 3월 7일
sir, my problem is not accessing the values...I need to store it in a variable...after this,the variable contains 1X10 values and it will be used in future...

댓글을 달려면 로그인하십시오.


Hyetan Lee
Hyetan Lee 2012년 3월 7일
hi harjan.
So, your data type is string now, and it is in the cell matrix(256x10). Am I right?
Then, you can't access it like a variable.
Try this.
------------------------------------------------
test_str = [{'1'} {'2'} {'3'}; {'4'} {'5'} {'6'}; {'7'} {'8'} {'9'}];
% test_str is cell(3x3) matrix with string 1~9
test_char = char(test_str);
% convert to character array first
test_var = str2num(test_char);
% convert to number now
------------------------------------------------
I hope it can help you.
The point is, it's not a cell but string.
  댓글 수: 1
harjan
harjan 2013년 10월 5일
Yes It works now thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by