Convert a cell in a field from string to number
조회 수: 1 (최근 30일)
이전 댓글 표시
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
%% Load xypts
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 :)
댓글 수: 0
답변 (1개)
Walter Roberson
2022년 9월 21일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!