Matlab Online won't update logical variable in the workspace.
Show older comments
Just encountered this issue in the following example. When I run this code in MATLAB Online, the result is correct, so I know that the value of is_prime is updated correctly during runtime. However, when I check the value of is_prime in the workspace, it does not get updated. For example, when the condition rem(n, number) == 0 is satisfied, is_prime should become false, but in the workspace, it still shows true. Interestingly, when I double-click on the value, it displays the correct value in a separate window. Is there a reason why this happens? The other variables are updated correctly.
n = 6;
is_prime = true; % flag variable
for number = 2:n-1
% check if the value n is divisbile by the index "number"
if rem(n,number) == 0
is_prime = false;
fprintf("%d is not a prime number! divisible by %d\n",n,number)
end
end
is_prime
if is_prime
fprintf("Prime number")
else
fprintf("Not a prime number")
end
2 Comments
Walter Roberson
on 17 Sep 2024
I tested out in MATLAB R2024b desktop, and I tested out in MATLAB Online. I am not able to replicate the variable showing up as true.
Steven Lord
on 17 Sep 2024
I tried this in the desktop version of R2024b like Walter did. Like Walter I was not able to reproduce this behavior, either with the display of the variable in the Command Window or with the display in the Workspace component of the Desktop.
Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!