MATLAB Solving MATLAB Duplication Error with For Loop

  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
  • Tags Tags
    Error Matlab
AI Thread Summary
The discussion centers around a user new to MATLAB experiencing unexpected duplicate outputs from a for loop that calculates and displays the absolute values of the tangent function for integers 1 through 10. The user initially reports that the output appears twice, prompting questions about the cause. Responses suggest that the issue may stem from accidental double execution of the code, possibly due to user error or interface quirks. Another participant mentions that the code worked correctly in an earlier version of MATLAB (R2012a) without duplication. The conversation also touches on using the "clc" command, which clears the command window, potentially helping to avoid confusion with previous outputs. Overall, the discussion highlights common troubleshooting steps and user experiences in MATLAB programming.
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?
 

Similar threads

Back
Top