필터 지우기
필터 지우기

Convert string to a cell, array or matrix

조회 수: 2 (최근 30일)
Alfonso Lopez
Alfonso Lopez 2015년 11월 27일
댓글: Alfonso Lopez 2015년 11월 30일
Hi everyone,
I was wondering how I could convert an string to array or matrix.
Thanks very much.

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 11월 30일
Hi Alfonso,
first of all, you might consider using the variable "NUM", since it already contains the numbers as double variable. So no need to convert anything. You usually use the RAW format, when the format of the EXCEl file changes, i.e., the indexing into NUM get's more complicated. If RAW(2:end, 65) contains only numbers (as numbers, not strings), probably simply doing
FaceRecall = cell2mat(RAW(2:end, 65));
or
FaceRecall = [RAW{2:end, 65}]';
should both work ...
Titus
  댓글 수: 2
Titus Edelhofer
Titus Edelhofer 2015년 11월 30일
But as I said, maybe
NUM(:, 65)
leads to the same ...
Titus
Alfonso Lopez
Alfonso Lopez 2015년 11월 30일
Yes, the two answers works very good. Thanks very much!! :)

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

추가 답변 (2개)

Titus Edelhofer
Titus Edelhofer 2015년 11월 27일
What about this one:
doc str2num
Titus
  댓글 수: 1
Alfonso Lopez
Alfonso Lopez 2015년 11월 27일
I've tried to do this but unfortunately the output is 0... Could you give any other example which I could extrapolate to my data, please?

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


Thorsten
Thorsten 2015년 11월 27일
A string is a 1Xn matrix of type char
S = 'hallo';
You can convert it to a numerical matrix using
M = double(S);
If that is not what you want, please give us more details, and a sample string.
  댓글 수: 2
Alfonso Lopez
Alfonso Lopez 2015년 11월 27일
Sorry I'm a beginner in this. I put all I did until moment:
[NUM,TXT,RAW]=xlsread('data.xlsx'); % Open excel data
condition=RAW(2:end,121); % CONDITIONS
subject=RAW(2:end,118); % SUBJECTS
FaceRecall=RAW(2:end,65); % Asign variable
The problem is that this variable appear "{}FaceRecall" in my workspace and when I try to do the mean appears a mistake. I think it's because is not a numeric variable so I would like to know how to convert it.
I don't know if I explain in the best way. Sorry for my English.
Thorsten
Thorsten 2015년 11월 27일
Please post the data.xlsx file such that we can have a closer look.

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by