Borrar filtros
Borrar filtros

Matlab Mutiple Text Files, Plot

3 visualizaciones (últimos 30 días)
Matlab User
Matlab User el 19 de Ag. de 2016
Editada: Matlab User el 29 de Ag. de 2016
can anyone please help me with this questions?
I plotted multiple files using the two while loops in the Matlab Editor --> run,but when I tried to plot the files using GUI pushbutton, I got this error message for some of the files..
Error using plot Vectors must be the same length.
fid= fopen([FilesToRead, MultipleFiles]);
Block=0;
while true
tLine = fgetl(fid);
if ~ischar(tLine)
break;
else
headerCells = strsplit(tLine,' ');
if length(headerCells) > 1
if ~isempty(headerCells{2})
if ~strcmpi(headerCells{2},'!user') && ~strcmpi(headerCells{2},'data')
textForGUI = headerCells{2}
end
end
end
end
if ~isempty(strfind(tLine,'data'))
Block=Block+1;
fprintf('\n\nBlock: %s\n\n', num2str(Block));
formatSpec = '%f %f %f %f %f';
C = textscan(fid,formatSpec,24,'CommentStyle','data','Delimiter','\t');
%here I got some calculations and plots
% I have for loop to handles indexing
end
end
end

Respuesta aceptada

Guillaume
Guillaume el 19 de Ag. de 2016
Well, the error message is very clear:
Error using plot. Vectors must be the same length
Error in [..] plot(Column4, CalcValue(:,1), '-rs');
Column4 and CalcValue(:, 1) are not the same length. That is the basic problem.
Note that if CalcValue has more than one column, then the line
Column4(end:end+numel(CalcValue)-numel(Column4))=nan;
is guaranteed to make Column4 longer than CalcValue(:, 1). Perhaps you meant:
Column4(end:end+size(CalcValue, 1)-numel(Column4))=nan; add as many nans as there are extra rows in CalcValue
  2 comentarios
Matlab User
Matlab User el 19 de Ag. de 2016
Editada: Matlab User el 29 de Ag. de 2016
it's not working.
Guillaume
Guillaume el 19 de Ag. de 2016
If all the plotted points are separated by nans, you would get only red squares:
xy = reshape([1:10; nan(1, 10)], 1, []) %values separated by nans
plot(xy, xy, '-rs')
I have no idea if that is your issue or not. Look at what's in CalcValue(:, 1) and Column4.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by