필터 지우기
필터 지우기

@findall in an arrayfun?

조회 수: 3 (최근 30일)
David L
David L 2021년 1월 6일
댓글: Star Strider 2021년 1월 7일
Hi,
I'm having trouble using findall as an arrayfun. In AppDesigner, I'd like to find all objects whose 'Tag' has 'img' in it - I have lots of uiimages, img_1, img_2... img_25, and then run a function on all these uiimages?
I've tried the following:
arrayfun(@findall,0, 'Tag', a);
where a = is a cell array of strcat of 'img_' + num2str(n);
a = cell(25,1);
for i = 1:25
a{i} = strcat('img_',num2str(i));
end
Thanks!

채택된 답변

Star Strider
Star Strider 2021년 1월 6일
The cellfun function is likely a better option.
Experiment with something like this:
Out = cellfun(@(x)findall(0,'Tag','img'), a, 'Unif',0);
It will likely be necessary to experiment with that to get it to work with your images.
I cannot test this with your images, so I am posting it as UNTESTED CODE. (If it or some version of it does not work in your application, I will delete my Answer.)
  댓글 수: 4
David L
David L 2021년 1월 6일
Thank you all very much for your answers! Steven, I'll think about linking all my images to a parent object - which might make getting their handles easier.
In the end, I went with your approach, Star and Walter, and Walter your response worked perfectly. Again, thank you all very much.
Star Strider
Star Strider 2021년 1월 7일
As always, (our) pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Steven Lord
Steven Lord 2021년 1월 6일
As written this will find all graphics objects with those Tag values, those that are part of your app and those that are not. That strikes me as a Bad Idea. Instead, if you're displaying those images in your app I'd store their handles in a property of your app and then simply iterate through the elements of that property. This example doesn't use an app but shows the technique I have in mind.
f = figure;
ax = axes('Parent', f);
axis([0 360 -1 1])
hold on
x = 0:360;
h = gobjects(1, 5);
for k = 1:5
h(k) = plot(x, sind(k*x), 'DisplayName', "sine of " + k + "*x");
end
legend show
Now I can change a subset of the lines without using findobj or findall just by indexing into h.
h(1).LineStyle = '--';
h(3).Color = 'k';
h(5).Marker = '^';
h(5).MarkerIndices = 1:30:361;

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by