Effacer les filtres
Effacer les filtres

Storing arrays with guidata/Userdata

3 vues (au cours des 30 derniers jours)
Mason
Mason le 13 Nov 2023
Réponse apportée : Mason le 14 Nov 2023
Im having a hard time wrapping my head around how I might go around storing an array for later use using my gui. I want to be able to store an array called LN using a pushbutton but im not entirely sure how to tackle it. I dont need anything too complex I just want to be able to see an example and figure out where to start. Ive looked over guidata and Userdata functions. I came to the conclusion guidata may be more functional for my current project, but other than using it within a figure, im not sure how to store LN with the press of the pushbuttons I have.
  5 commentaires
Mason
Mason le 14 Nov 2023
How might I go about that? Everytime a new value is input LN is reset to zero
Mason
Mason le 14 Nov 2023
Actually I figured it out, i just had to move a value outside the function

Connectez-vous pour commenter.

Réponse acceptée

Mason
Mason le 14 Nov 2023
I figured out how to save data without gui data. It was as simple as using "persistent" in my function.
Although it may not be the best way, it works as I need it to.
function NumberBook(CT,T) % <- pass LN to the function
persistent LN
if T == -1
clear LN
elseif CT == 1 % Start of counter
LN = zeros(1,10); % Allocated space | 10 Digit restriction (Implimented later on)
N = zeros(1,10);
N(CT) = T; % Adds number to array
LN = LN + N;
disp(LN)
elseif CT >= 1
N = zeros(1,10);
N(CT) = T; % Adds number to array
LN = LN + N;
disp(LN)
end
end
Giving me an actual number when a number is inputted, rather than just being zeros and a new value.
ans =
6 2 2 3 2 3 5 0 0 0
ans =
6 2 2 3 2 3 5 0 1 0
ans =
6 2 2 3 2 3 5 0 1 6

Plus de réponses (1)

Walter Roberson
Walter Roberson le 14 Nov 2023
function Myproj_Button1_Callback(hObject, event, ~)
handles = guidata(hObject) ;
handles.LN = magic(7);
guidata(hObject, handles);
function Myproj_GoButton(hObject, event, ~)
handles = guidata(hObject);
LN = handles.LN;
If you are using guide then some simplifications are possible

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by