Solving MATLAB Duplication Error with For Loop

  • Context: MATLAB 
  • Thread starter Thread starter Superposed_Cat
  • Start date Start date
  • Tags Tags
    Error Matlab
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB duplication error encountered while using a for loop to display values. Participants explore potential reasons for the unexpected repeated output and suggest troubleshooting steps.

Discussion Character

  • Technical explanation, Debate/contested, Meta-discussion

Main Points Raised

  • One participant shares their MATLAB code and notes that the output is displayed twice.
  • Another participant reports that the same code produced a single output when run in a different version of MATLAB (R2012a).
  • A participant mentions that the issue resolved itself upon re-running the code without any changes, but also experienced a duplication with a graph.
  • One participant humorously speculates about possible user error, suggesting that the original poster might have inadvertently triggered the duplication.
  • Another participant comments on the interface behavior, noting that the button becomes non-clickable after one press.
  • A suggestion is made to use the "clc" command before running the script to potentially address the issue.
  • A follow-up question is raised about the purpose of the "clc" command.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the duplication error, with multiple competing views and experiences shared regarding the issue.

Contextual Notes

Some assumptions about user behavior and software interface interactions are present, but these remain unresolved. The discussion does not clarify the specific conditions under which the duplication occurs.

Who May Find This Useful

New MATLAB users, individuals troubleshooting similar output issues, and those interested in programming practices may find this discussion relevant.

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

  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 9 ·
Replies
9
Views
2K