Add legend labels to array of smith plots - error "Unable to perform assignment..."

19 次查看(过去 30 天)
I am facing this weird issue with smithplot when trying to assign individual legend labels from a cell array.
My legends look like this:
smith_legends = {'S11 reflection','S21 shunt','S21 series'};
I am creating a set of 3 superimposed smith charts in a loop where an array of handles is created. As an example:
for idx = 1:3
smith_handles(idx) = smithplot(freq, Sxx, 1,1, 'GridType','Z');
% smith_handles(idx).LegendLabels = smith_legends(idx); % --> line that fails
hold on
end
where freq and Sxx are my data pairs (Sxx is a complex matrix)
When assigning the labels, I get this: (why there are more legends than datasets?! why the colors don't match?)
with the following error after the first assignment:
Now, I have also tried assigning the three labels without indexing. Interestignly, I get the same error, HOWEVER, the legend labels are successfully assigned!
Why Matlab insists with throwing this error: "Unable to perform assignment with 0 elements on the right-hand side."
Why "0 elements"?! if the labels are there!
  2 个评论
Adam Danz
Adam Danz 2022-7-29
It would be easier to troubleshoot if we could reproduce these results. You would need to provide the input data and relevant code.
Daniel Melendrez
Daniel Melendrez 2022-7-30
Dear Adam
Thank you for the kind comment. Apologies for the late reply.
I actually figured out a solution. I will be sharing it shortly.
Cheers

请先登录,再进行评论。

回答(1 个)

Daniel Melendrez
Daniel Melendrez 2022-8-1
Here I am answering my own question.
Prior to doing that I must say that the information regarding the use of the smithplot is importantly incomplete and not so many examples can be found. Most of the examples are based on .sp2 files and just a few use Z=Re+jIm data formats. Moreover, the explanation on how to use the smithplot properties is lacking (from here)
This is my solution:
Instead of treating the smithplot handles as an array, I created a handle object first:
smith_handle = smithplot;
this handle is passed to a function that creates the smith charts from my data pairs (freq and Z), as follows:
function sp_handle = plot_smith_chart(sp_handle, freq, Z) % showing the function header here
then, inside this function I use the add function:
add(sp_handle, freq, Z)
I use my function inside a loop to create my superimposed smith charts from a data matrix:
for idx = 1:3
smith_handle = plot_smith_chart(smith_handle, frequencies, Zxx);
end
Finally, once the loop is complete, I assign the labels from a cell:
smith_legends = {'S11 reflection','S21 shunt','S21 series'};
smith_handle.LegendLabels = smith_legends;
Which successfully creates my set of smith charts with matching colours:
I am not a big fan of this solution, however if it works, I am ok with that! (for now)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by