"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)
Mostrar comentarios más antiguos
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
Respuestas (1)
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
size(ax.XAxis) % scalar
size(ax.YAxis) % non-scalar
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
Instead, use set() to set properties of non-scalar arrays of graphics objects:
set(ax.YAxis,'LineWidth',3); % no error
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
