See the image
I want to count with the 1st column, but I always get the message "Undefined operator" - "for input arguments or type 'cell'." What can I do about it? I think the column is not numeric, but I am not sure. Who can help me?

댓글 수: 8

Rik
Rik 2018년 6월 6일
You should really consider a tutorial in Matlab. If you plan on using Matlab it is really worth it to invest the time in learning how to work with it. Have you tried cell2mat?
jakobjakob
jakobjakob 2018년 6월 6일
Yes i tried it, but I couldn't calculate with it. It is something with 'double'. It is NOT numeric, cell array or string. I tested that with isstring etc. Can you help me?
Rik
Rik 2018년 6월 6일
A double is a double precision floating point number: a numeric data type. Did you include the header text in the array you put into cell2mat?
I tested that with isstring etc.
We cannot read your mind. What is "etc."? What did you try and what did you get as answer? Do you see that the decimal separator is a comma? Then this cannot be numeric values, because Matlab uses a dot. You did not mention, where you got this screenshot from.
jakobjakob
jakobjakob 2018년 6월 6일
@Rik No I didn't include the header, only the numbers
jakobjakob
jakobjakob 2018년 6월 6일
@Jan, it is a screenshot of an excelsheet, so that's why there are commas. In matlab there are dots. When I use the commando iscell it gives a '1'. Can you help me further?
jakobjakob
jakobjakob 2018년 6월 6일
편집: jakobjakob 2018년 6월 6일
I uploaded the variable, its about the variable ndata

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

 채택된 답변

Stephen23
Stephen23 2018년 6월 6일
편집: Stephen23 2018년 6월 6일

2 개 추천

Where C is your cell array:
V = str2double(C(:,1))
This assumes that there is no header, and that each cell of the first column contains one number stored as a char (using a dot, not comma).

댓글 수: 9

jakobjakob
jakobjakob 2018년 6월 6일
Thanks, but when I do that, V is column with only NaN...
Stephen23
Stephen23 2018년 6월 6일
@jakobjakob: then your description is not adequate for us to know what data you actually have. If you want further help with this please upload that variable in a .mat file by clicking the paperclip icon.
jakobjakob
jakobjakob 2018년 6월 6일
I uploaded the variables, it is about the variable ndata
Stephen23
Stephen23 2018년 6월 6일
편집: Stephen23 2018년 6월 6일
ndata is already numeric. It has class double. You can check this using whos.
If you want to generate ndata from alldata, then the first column of alldata already contains numeric values, so you don't need to convert anything, just join then together into a numeric vector:
ndata = vertcat(alldata{:,1})
ndata = cell2mat(alldata(:,1))
jakobjakob
jakobjakob 2018년 6월 6일
편집: jakobjakob 2018년 6월 6일
Thanks, but my real problem is that I want to calculate with the first column of alldata. That is still not possible. For example: alldata(1,1) - 10. Can you help me with that?
alldata(1,1) returns a cell. The ndata variable that either line of Stephens code produces will work with this syntax.
ndata = cell2mat(alldata(:,1));
alldata(1,1) - 10
jakobjakob
jakobjakob 2018년 6월 6일
Thanks!
Stephen23
Stephen23 2018년 6월 6일
편집: Stephen23 2018년 6월 6일
@jakobjakob: The concept for indexing cell arrays is simple:
  • {} curly braces access the data inside the cells.
  • () parentheses access the cells themselves.
Just think of cell arrays like boxes: do you want to pick up the box (the cell, ()), or whatever that is inside the box (the data, {}). Sometimes you want to pick up the box, and sometimes you want to get out whatever is inside... each of these can be useful.
Therefore to access the contents of one cell you just need to use curly braces:
alldata{1,1} - 10
jakobjakob
jakobjakob 2018년 6월 6일
Thanks a lot! Such a simple solution...

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2018년 6월 6일

댓글:

2018년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by