"Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list assignment." Error only sometimes happens.

68 visualizaciones (últimos 30 días)
I'm getting the error "Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list assignment." from the code snippet below. The error happens on the line that says "ax.YAxis.LineWidth = 1.5"
hold on
plot(str2double(cold.S22_IO.freq_Ghz(2:end)), str2double(cold.S22_IO.meas22_db(2:end)), 'color', 'b', 'LineWidth', 1.5)
plot(str2double(ambient.S22_IO.freq_Ghz(2:end)), str2double(ambient.S22_IO.meas22_db(2:end)), 'color', 'g', 'LineWidth', 1.5)
plot(str2double(hot.S22_IO.freq_Ghz(2:end)), str2double(hot.S22_IO.meas22_db(2:end)), 'color', 'r', 'LineWidth', 1.5)
specx = str2double(S22_AS.freq_Ghz(2:end));
specy = str2double(S22_AS.spec(2:end-1));
plot(specx, specy, 'color', '#000000', 'LineWidth', 1, 'LineStyle', '--')
xline(.15, '--', 'color', 'k', 'LineWidth', 1), xline(2, '--', 'color', 'k', 'LineWidth', 1)
hold off
axis([0 2.5 -40 0])
ylabel("|S22| (dB)")
xlabel("Frequency (GHz)")
legend("0C", "25C", "60C", "spec")
ax = gca;
ax.TitleFontSizeMultiplier = 1.5;
ax.XAxis.LineWidth = 1.5;
ax.YAxis.LineWidth = 1.5;
set(gca, 'fontweight', 'bold')
grid on
tick = 0:.25:3;
set(gca, "XTick", tick);
plotname = strcat("LB_SN", serial_number, "_J2_Output_Return_Loss");
title(strrep(plotname, '_', ' '))
saveas(gcf, fullfile(currentFolder, "test4", plotname), "jpeg")
test4_files = strcat(plotname, ".jpg");
clf
What does this error mean and is there a better way to write this that might prevent the error in the future?
Whats most confusing is that the error only happens sometimes and only in this block of code. If I run the script after getting the error the problem fixes itself for a couple of runs. There are also other very similar pieces of code in the script that have the same exact line but dont encounter this error.
Any ideas or help on this is appreciated.
  1 comentario
Stephen23
Stephen23 el 28 de Nov. de 2023
Editada: Stephen23 el 4 de Dic. de 2023
The problem is very simple: sometimes AX.YAXIS is non-scalar. Lets try it right now:
A(1:2).B = pi
Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list assignment.
For an explanation of comma-separated lists:

Iniciar sesión para comentar.

Respuestas (1)

Voss
Voss el 3 de Dic. de 2023
If you have two y-axes, then ax.YAxis is non-scalar, so
ax.YAxis.LineWidth = 1.5;
gives you an error.
Notice that the previous line apparently ran without error:
ax.XAxis.LineWidth = 1.5;
because there's only one x-axis.
Example, use yyaxis() to create an axes with two y-axes and one x-axis:
f = figure();
yyaxis('left');
plot(1:10);
yyaxis('right');
plot(10:-1:1);
Check the sizes of ax = gca(), ax.XAxis, and ax.YAxis:
ax = gca();
size(ax) % scalar
ans = 1×2
1 1
size(ax.XAxis) % scalar
ans = 1×2
1 1
size(ax.YAxis) % non-scalar
ans = 1×2
2 1
Set the LineWidth of ax.Xaxis (no problem):
ax.XAxis.LineWidth = 3; % no error because there is only one XAxis
Try the same thing with ax.YAxis (error):
try
ax.YAxis.LineWidth = 3; % error because there is more than one YAxis
catch ME
disp(sprintf('Error: %s',ME.message));
end
Error: Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list assignment.
Instead, use set() to set properties of non-scalar arrays of graphics objects:
set(ax.YAxis,'LineWidth',3); % no error

Categorías

Más información sobre Graphics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by