X and Y must be same length, however they already are?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Deniz Mert Yayla
el 19 de Oct. de 2019
Comentada: Deniz Mert Yayla
el 19 de Oct. de 2019
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?
1 comentario
Respuesta aceptada
Walter Roberson
el 19 de Oct. de 2019
You do not store any x values, so it is [] after the reading loop.
3 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Large Files and Big Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!