Why does my for loop display output twice in MATLAB?

  • Context: MATLAB 
  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
  • Tags Tags
    Error Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
6 replies · 3K views
Superposed_Cat
Messages
388
Reaction score
5
Hi, I'm totally new to MATLAB and tried this for loop

Code:
for K = 1:10
  disp(abs(tan(K)))
end

it displays
Code:
1.5574
 2.1850
 0.14255
 1.1578
 3.3805
 0.29101
 0.87145
 6.7997
 0.45232
 0.64836

 1.5574
 2.1850
 0.14255
 1.1578
 3.3805
 0.29101
 0.87145
 6.7997
 0.45232
 0.64836

Why did it display this twice?
Thanks for any help.
 
Physics news on Phys.org
The shortest answer is that it only displayed it once for me when I ran the same code in R2012a.
 
Thanks, When I did it again it worked without changing anything but it happened again and duplicated a graph.
 
If you don't show me anything to go with, I can only assume you sneezed while hitting enter, or that you were drunk and seeing double.
 
lol, the button only allows you to press it once before changing to a animated non-clickable gear.
 
try "clc" before the script
 
whats that do?