MATLAB: Matlab Mutiple Text Files, Plot

MATLABtext files

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

Best Answer

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