c = -1;
Arr = [[]];
fprintf("Release of imaginary units: \n");
for i = 1:4
c = c*-1;
fprintf("%d ",c);
Arr(1,i) = c;
end
fprintf("\n");
for i = 1:4
Arr(2,i) = toggle(Arr(1,i));
fprintf("%d ",Arr(2,i));
end
C = 1;
fprintf("\n");
for i = 1:4
fprintf("%d ",C)
if(mod(i,2)==1)
Arr(3,i) = toggle(C);
C = Arr(3,i);
else
Arr(3,i) = C;
end
end
fprintf("\n");
C = -1;
for i = 1:4
fprintf("%d ",C)
if(mod(i,2)==1)
Arr(4,i) = toggle(C);
C = Arr(4,i);
else
Arr(4,i) = C;
end
end
fprintf("\n");
for i = 1:4
Arr(5,i) = toggle(Arr(3,i));
fprintf("%d ",Arr(5,i));
end
fprintf("\n");
for i = 1:4
fprintf("%d ",Arr(3,i))
if(mod(i,2)==1)
Arr(6,i) = toggle(Arr(3,i));
C = Arr(6,i);
else
Arr(6,i) = C;
end
end
function res = toggle(n)
if(n<0)
res = 1;
else
res = -1;
end
end
Cite As
Hoi Sing Lau (2025). One and minus one (https://se.mathworks.com/matlabcentral/fileexchange/182422-one-and-minus-one), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2025a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Acknowledgements
Inspired by: Plus and Minus
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
