how to build array using matlab.gra​phics.char​t.primitiv​e.Line' property

Look this example:
selected = findobj(allLines,'Type','line','LineWidth',0.5);
[cc]=selected;
selected 13x1
xx selected 13x1
this is ok
now i try to use selected property:
selected.Color
it give me 13x1 color!
now i try to record information in array but it's not possible
[cc]=selected.Color
now i see cc have only the first element!
can i do it?

 Respuesta aceptada

If I understand correctly, you want cc to just be the color of the selected lines. In that case, note that selected.Color does not return a 13x1 array, It returns 13 1x3 arrays. Try the following instead.
z = rand(10,13);
plot(z)
selected = findobj(gcf,'Type','line','LineWidth',0.5);
cc=selected
cc =
13×1 Line array: Line Line Line Line Line Line Line Line Line Line Line Line Line
cc=vertcat(selected.Color)
cc = 13×3
0.1840 0.7450 0.9370 0.2310 0.6660 0.1960 0.5210 0.0860 0.8190 0.9290 0.6940 0.1250 0.8660 0.3290 0 0.0660 0.4430 0.7450 0.8190 0.0150 0.5450 0.1840 0.7450 0.9370 0.2310 0.6660 0.1960 0.5210 0.0860 0.8190 0.9290 0.6940 0.1250 0.8660 0.3290 0 0.0660 0.4430 0.7450
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
You can find a longer explanation of what is happening here: https://www.mathworks.com/matlabcentral/answers/29190-property-access-of-objects-arrays

5 comentarios

thank you
but if i want to change this color and convert it as follow: (i want to add trasparency in all array)
[0.1 0.1 0.3] =====>[0.1 0.1 0.3 0.5]
[0.2 0.3 0.1] ======> [0.2 0.3 0.1 0.5]
How do you suggest I change it the fastest?
set(selected, {'Color'}, cellfun(@C, [C,0.5], {selected.Color}, 'uniform', 0))
shamal
shamal el 7 de Jun. de 2025
Editada: shamal el 7 de Jun. de 2025
Unrecognized function or variable 'C'.
Error in mycallback (line 17)
set(selected, {'Color'}, cellfun(@C, [C,0.5], {selected.Color}, 'uniform', 0));
Error while evaluating Line ButtonDownFcn.
(i execute it in function mycallback(o,~) )
z = rand(10,13);
plot(z)
selected = findobj(gcf,'Type','line','LineWidth',0.5);
set(selected, {'Color'}, cellfun(@(C) {[C,0.5]}, {selected.Color}.'))
good...thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 7 de Jun. de 2025

Comentada:

el 8 de Jun. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by