【问题标题】:Error using plot Not enough input arguments使用绘图时出错没有足够的输入参数
【发布时间】:2015-09-03 17:37:23
【问题描述】:

我是matlab新手。当我尝试导入数据文件并绘制它时,它显示错误“使用绘图时输入参数不足”。我使用了以下代码。

filename = '/home/mydata.dat';
delimiter = '\t';
formatSpec = '%s%s%[^\n\r]';
fileID = fopen(filename,'r');
datacell= textscan(fileID, formatSpec, 'Delimiter', delimiter,  'ReturnOnError', false);
Time=datacell{1};
iv1=datacell{2};
plot(Time,iv1);
fclose(fileID);

【问题讨论】:

  • 您正在尝试绘制单元格,plot 而是使用数组。我还怀疑单元格包含字符串,也不适合绘图。
  • 能否提供 mydata.dat 文件的内容(或样本)?
  • datacell的内容是什么?

标签: matlab


【解决方案1】:

您的formatSpec 有字符串,即%s%s?如果是这样,那就有问题了。在绘图之前,您需要将字符串转换为数字。

您可以通过两种不同的方式将字符串转换为数字,如下所示。代码在我的Saturn Fiddle 上供您测试。

% Welcome to SaturnAPI!
% Start collaborating with MATLAB-Octave fiddles and accomplish more.
% Start your script below these comments.

str2num ("3.141596")

str2num (["1, 2, 3"; "4, 5, 6"])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多