Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Help me check what is wrong with my code
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to print a table from a for loop with fprintf but when i run the code, it gives error
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in (line 47)
fprintf('%5s\t\t %5s\t\t %5s\t\t %5s\n',[data;t;time_for_iteration;s_new]);
this is the code with error below
fprintf('data\t\t t\t time_for_iteration\t s_new');
fprintf('%5s\t\t %5s\t\t %5s\t\t %5s\n',[data;t;time_for_iteration;s_new]);
data is 1x7 class double, t is 1x1 class double, time_for_iteration is 1x1 doubles_new is 1x1 double.
the remaining code is
[data]=([-1 2 -4 4 2 3 2]);
positive test algorithm
h=4; %threshold
s=0;
time_for_iteration=0;
for t=2:numel(data) %start time
s_new= s + data(t); %cumulative sum up to current value
if s_new > h %if output is greater than the specified threshold
%sound the alarm
detect_tim=t(s_new > h); %store the detection time
disp(['The detection time= ', num2str(detect_tim),'']) %display the detection time
% counter for algorithm
if s_new < 0
time_for_iteration=0;
else
time_for_iteration= time_for_iteration + 1;
end
% stop and reset algorithm
continue %to re-start algorithm
end
v=s_new;
end
Thank you
5 Kommentare
Walter Roberson
am 13 Aug. 2018
fprintf('%f\t%f\t%f\t%f\n', [var1(:), var2(:), var3(:), var4(:)].' );
Antworten (0)
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!