How to replace certain values in an existing array based off of inputdlg?
Mostra commenti meno recenti
In this gui I have been coding, I generate some m x n dimensional array with a function I have written. What I want to know is: how can I replace certain values in this array from another function? I am using the GUIDE GUI program with callbacks.
I want to take user input from a dialog box and assign those values to variables for use in an equation I have written.
function edit_button_Callback(hObject, eventdata, handles)
% hObject handle to edit_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
prompt ={'Param1' 'Param2' 'Param3' 'Param4' 'Param5' 'Location'};
dlg_title = 'Input';
num_lines = 1;
def = {'vectorinput1','vectorinput2','vinput3','vinput4','vinput5','index'};
def = def';
deff = cellstr(def);
answer = inputdlg(prompt, dlg_title, num_lines, deff);
[Rsh, Rs, Isc, Voc, n, index] = answer{:};
That also doesn't seem to be working at the moment. Anyway, after I have the user input values for the parameters, I would use the equation I have written to generate a column array and a row array. How would I be able to change the values in an already existing array based on the location specified in the inputdlg?
Risposta accettata
Più risposte (1)
Joseph Cheng
il 13 Ago 2014
Modificato: Joseph Cheng
il 13 Ago 2014
i think that last line should be
[Rsh, Rs, Isc, Voc, n, index] = deal(answer{:});
for it to split answer into the different variables.
So if i understand the rest of your question correct, you have a mxn array. Lets call that X and based on what [Rsh, Rs, Isc, Voc, n, index] (perhapse n and index?). you want to replace it with something else. then you can go
X(n,index) or something along that line to specify the row and column intersection. such that if i go:
X = [1 2 3;4 5 6;7 8 9];
X(2,3) = 1;
then the second row third column would then be replaced with 1.
10 Commenti
Roel
il 13 Ago 2014
Roel
il 13 Ago 2014
Joseph Cheng
il 13 Ago 2014
I don't see where you're trying to perform the substitution. is the substitution going on in the edit_button callback? or in another callback.
Roel
il 13 Ago 2014
Joseph Cheng
il 13 Ago 2014
well, since it would take a lot of time i don't really have right now to understand the things that's going on and describe what you fully need to implement the substitution I'll just talk vaugely.
Just like your CalculationIVRsRsh callback in the plot_button you have
for ind=1:taille
[I(:,ind), V(:,ind)]=CalculationIVRsRsh(Isc(ind),Voc(ind),T,n(ind),Rs(ind),Rsh(ind));
end
which is basically what i showed you above in the X(2,3) =1 case. such that if we just take those lines you see that in the for loop you are actually building the I and V arrays index by index. However since i show you can specify the ind, you can directly index whatever you want. I think Amir's example below should be a good example of how to pass the original variable calculated from the plot callback. (i haven't look at his example but its probably good).
Roel
il 13 Ago 2014
Roel
il 13 Ago 2014
Amir
il 14 Ago 2014
Roel Yes you can do that also. You need to add some other controllers. 1) Add a radio button asking the user for :is it a range? (Yes/NO) 2) Add another text box which is for the last point of your data range. 3) If the user's selection (in radio button) is not "Yes", you can disable the second text box (step 2) which is for the range. use this:
set(handles.edit, 'Enable', 'off')
You can also code to your static texts to be changed based on you radio button value. If this couldn't help you please let me know then I can attach a simple example for you. And the last point, try this code:
A='2+3';
A
B=eval(A)
If your app's users are familiar with Matlab's syntax you can use eval. I mean you can evaluate user's string (which has been typed in text box, for example '[1:3]') and convert it to meaningful syntax which can be run in Matlab. Here is an example
A=[1 2 3 4 5 6 7 8 9 10];
B='3:5';
% B is a string variable similar to what you get from textbox in gui
A(eval(B))
Roel
il 14 Ago 2014
Amir
il 14 Ago 2014
I hope the attached files help you Roel.
Categorie
Scopri di più su Migrate GUIDE Apps in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!