Matlab Mutiple Text Files, Plot
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!