# Convert a cell in a field from string to number

3 views (last 30 days)
Jack on 21 Sep 2022
Commented: Walter Roberson on 21 Sep 2022
Hi everyone. I'm having an issue as I'd like to graph some data but can't becuase it is in a string and dont know how to convert it to a number. I load the points from a tsv file with the following
points.samp{1}=tdfread('samp1xypts.tsv',';'); %load data points from particle tracking
points.samp{2}=tdfread('samp2xypts.tsv',';'); %load data points from particle tracking
points.samp{3}=tdfread('samp3xypts.tsv',';'); %load data points from particle tracking
points.samp{4}=tdfread('samp4xypts.tsv',';'); %load data points from particle tracking
points.samp{5}=tdfread('samp5xypts.tsv',';'); %load data points from particle tracking
I then put the data into cell arrays with the following
for i=1:1:length(frames)
ind=find(points.samp{n}.Sparse_format_camera_coordinates_file(:,1)==frames(i));
points.sorted{n}(i+1,1) = frames(i);
points.sorted{n}(i+1,2) = points.samp{n}.Sparse_format_camera_coordinates_file(ind(1),3);
points.sorted{n}(i+1,3) = points.samp{n}.Sparse_format_camera_coordinates_file(ind(2),3);
points.sorted{n}(i+1,4) = points.samp{n}.Sparse_format_camera_coordinates_file(ind(3),3);
points.sorted{n}(i+1,5) = points.samp{n}.Sparse_format_camera_coordinates_file(ind(4),3);
end
Which looks like this
I would like to graph three collums of this data using a 3D plot. Say for example I chose the first cell array I get the following error message
y = points.sorted{1}(:,2);
x = points.sorted{1}(:,3);
z = points.sorted{1}(:,5);
p = plot3(x,y,z,'-g');
Error using plot3
Not enough input arguments.
Error in sortPoints (line 33)
p = plot3(x,y,z,'-g');
I suspect it is because the data is currently in string format as it works if I copy that data table into excel.... and then back into matlab again as a number and manually set up the vectors. Any help would be greatly appreciated. Thanks :)

Walter Roberson on 21 Sep 2022
I suspect it is because the data is currently in string format
x y z all need to be numeric for plot3() to work.
However, tdfread() should notice that all entries in the file are numeric other than the first row, and should create numeric output -- unless, that is, you have additional numeric rows that we cannot see from the diagram?
I recommend that you switch to using readmatrix() or readtable()
##### 2 CommentsShowHide 1 older comment
Walter Roberson on 21 Sep 2022
I would suggest that you convert to using table() objects.

### Categories

Find more on Localization Algorithms in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!