X and Y must be same length, however they already are?

3 次查看(过去 30 天)
So I am trying to run the following code:
x = [];
y = [];
fid = fopen('HWPlotting.dat');
if fid == -1
disp('Error:Cannot open file')
else
total = 0;
while ~feof(fid)
str = fgetl(fid);
str = str(3:end);
[xstr, rest] = strtok(str, 'y');
y = [y, str2double(rest(3:end))];
total = total + 1;
end
closeresult = fclose(fid);
if closeresult == 0
disp('File closed')
end
end
area(x,y)
xlabel('x')
ylabel('y')
title([num2str(total),' data points'])
However I get the error two errors:
"Error using area (line 52)
X must be same length as Y.
Error in HWPlotting (line 25)
area(x,y)"
The .DAT file I use is simple, it's like this and nothing else:
x 0 y 1.1
x 1.3 y 2.2
x 2.2 y 6
x 3.4 y 7.4
So what's really going on? What in this code is not the same length?

采纳的回答

Walter Roberson
Walter Roberson 2019-10-19
You do not store any x values, so it is [] after the reading loop.
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Large Files and Big Data 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by