フィルターのクリア

Create an exact Copy of a UIAxes in a different Tab in a Matlab App

9 ビュー (過去 30 日間)
Janno
Janno 2023 年 11 月 29 日
編集済み: Ayush Anand 2023 年 12 月 14 日
I would like to copy a UIAxes from one Tab to another. I have one Tab where you can look at the plots and now i want to create a second Tab where i can compare the UIAxes i already have to another one. But when i simply copy the UIAxes, it automatically creates UIAxes_2 and while it looks the same, i has none of the callbacks. i would like it to always be the exact same as the one i already have on the other tab, so when i change something in that tab, it automatically updates on the other one.
How can i make that copy? or do i have to put the callbacks on that one too? i tried by giving the "copy" the same callback but it didnt do anything. Probably bc the callbacks have UIAxes specified and UIAxes_2 is, well, obviously a different Axes. I dont want to copy paste all the code and specify it for UIAxes_2 aswell

回答 (1 件)

Ayush Anand
Ayush Anand 2023 年 12 月 14 日
編集済み: Ayush Anand 2023 年 12 月 14 日
Hi Janno,
In MATLAB, UI components like UIAxes are tied to their parent container (such as a figure or a tab). So, when copying a UIAxes, a new instance is created that doesn't share the callbacks or the interactive features of the original axes. To have two plots that are always synchronized, you need to update both plots whenever a change occurs.
This can be done by creating a function that updates both UIAxes whenever a change is made. This function would redraw the plot on both axes based on the same data source. Here is an example that shows the same:
% Create a figure with two tabs with UIAxes as uiAxes1 and uiAxes2
function updatePlots(data, uiAxes1, uiAxes2)
% Update plot on the first UIAxes
plot(uiAxes1, data.x, data.y);
% Update plot on the second UIAxes
plot(uiAxes2, data.x, data.y);
end
% Callback function that gets triggered on some event
function myCallback(src, event)
% Update both plots using the function defined earlier
updatePlots(data, uiAxes1, uiAxes2);
end
% Set the same callback for both UIAxes or related components
set(srcComponent1, 'ValueChangedFcn', @myCallback);
set(srcComponent2, 'ValueChangedFcn', @myCallback);
In this example, srcComponent1 and srcComponent2 are the components that trigger the callback (like a slider value changed or a button pushed). Since we have the same callback function for both UIAxes, the function “updatePlots” is called whenever any of the plots is interacted with and the changes are reflected in both.
You can read more about UI Figure Properties here:
I hope this helps!

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by