使用绘图函数时出错 - matlab

时间:2015-08-12 12:03:00

标签: matlab graph plot

我正在尝试使用以下代码使用plot函数

fid = fopen('data1.dat');
out = textscan(fid,'%s%f%f','delimiter','\t');
fclose(fid);
col1=out{1};
col2=out{2};
m=col1;
m1=col2;
disp(m1);
plot(m,m1);

但是我收到以下错误

Error using plot
Conversion to double from cell is not possible.

Error in sample (line 10)
plot(m,m1);

请使用此代码告诉我这里的错误。

1 个答案:

答案 0 :(得分:0)

您似乎采用了错误的单元格:col1=out{1};是一个带字符串的单元格数组。但你不能绘制字符串...

这是textscan

所得到的
out{1} = {'te' 'st' 'xt'};
out{2} = [ 12.3400
           23.5400
           34.9000 ];
out{3} = [ 12.3400
           23.5400
           34.9000 ]/2;

请参阅Matlab: textscan example

因此,您可以将col 3绘制为2以上。如果你想在你的col 1上绘图,你可以这样做:

plot(1:length(out{1}),out{2});
set(gca,'XTick',1:length(out{1}),'XTickLabel',out{1})

enter image description here