Matlab Mutiple Text Files, Plot

조회 수: 5 (최근 30일)
Matlab User
Matlab User 2016년 8월 19일
편집: Matlab User 2016년 8월 29일
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

채택된 답변

Guillaume
Guillaume 2016년 8월 19일
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
Matlab User
Matlab User 2016년 8월 19일
편집: Matlab User 2016년 8월 29일
it's not working.
Guillaume
Guillaume 2016년 8월 19일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by