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 Kommentare

Rik
Rik am 6 Jun. 2018
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 am 6 Jun. 2018
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 am 6 Jun. 2018
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 am 6 Jun. 2018
@Rik No I didn't include the header, only the numbers
jakobjakob
jakobjakob am 6 Jun. 2018
@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 am 6 Jun. 2018
Bearbeitet: jakobjakob am 6 Jun. 2018
I uploaded the variable, its about the variable ndata

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Stephen23
Stephen23 am 6 Jun. 2018
Bearbeitet: Stephen23 am 6 Jun. 2018

2 Stimmen

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 Kommentare

jakobjakob
jakobjakob am 6 Jun. 2018
Thanks, but when I do that, V is column with only NaN...
Stephen23
Stephen23 am 6 Jun. 2018
@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 am 6 Jun. 2018
I uploaded the variables, it is about the variable ndata
Stephen23
Stephen23 am 6 Jun. 2018
Bearbeitet: Stephen23 am 6 Jun. 2018
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 am 6 Jun. 2018
Bearbeitet: jakobjakob am 6 Jun. 2018
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 am 6 Jun. 2018
Thanks!
Stephen23
Stephen23 am 6 Jun. 2018
Bearbeitet: Stephen23 am 6 Jun. 2018
@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 am 6 Jun. 2018
Thanks a lot! Such a simple solution...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by