Need to stop warning because i need to not show a plot using compassplot

Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.

2 Kommentare

I don't recognize that as a warning from a MATLAB function.
Can you post the full code that gives that warning?
Simple testing does not appear to show that message?
compassplot([1 2+3i 2-3i])

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Norman
Norman am 19 Dez. 2025
Here is the code that gives the warning
X = compassplot(ones)

3 Kommentare

The function ones as called returns 1.
ones
ans = 1
Apparently, sending a real vector as the input generates that warning
figure;tiledlayout(1,2)
nexttile
X = compassplot(ones);
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.
nexttile
X = compassplot([1,-1]);
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.
To avoid the warnings, you can turn the warning off, plot, then turn back on.
[msgstring,warnid] = lastwarn % to see what the warning ID is
msgstring = 'Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.'
warnid = 'MATLAB:polar:AssumeComplex'
figure;tiledlayout(1,2);
nexttile
warnstruct = warning('off',warnid)
warnstruct = struct with fields:
identifier: 'MATLAB:polar:AssumeComplex' state: 'on'
X = compassplot(ones);
nexttile
X = compassplot([1,-1]);
warning(warnstruct); % return to previous state
Oddly enough, if you do provide something with real and imaginary components, you do not get the warning.
compassplot(1)
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.
compassplot(1+2i)
I can only guess from the text of the warning that the developers assume that if the user inputs a value with a non-zero imaginary part that the user meant it, but if the input has zero imaginary part then the user might be making a mistake (not sure what that mistake could be). But I could be wrong because the behavior is documented, though one could argue it could be a tad more clear on this particular case. Personally, I think this warning is overkill, though I'd be interested if there's some corner case where it helps keep the user from doing something unintended.
Note that the warning still shows up even if the input explicitly has a complex attribute
x = complex(1,0);
whos x
Name Size Bytes Class Attributes x 1x1 16 double complex
compassplot(x)
Warning: Plotting the real and imaginary components of the value provided. Specify both R and Theta values if you do not intend to plot a complex value.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2025b

Gefragt:

am 8 Dez. 2025

Kommentiert:

am 19 Dez. 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by