How to replace certain values in an existing array based off of inputdlg?
이전 댓글 표시
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?
채택된 답변
추가 답변 (1개)
Joseph Cheng
2014년 8월 13일
편집: Joseph Cheng
2014년 8월 13일
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
Roel
2014년 8월 13일
Roel
2014년 8월 13일
Joseph Cheng
2014년 8월 13일
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
2014년 8월 13일
Joseph Cheng
2014년 8월 13일
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
2014년 8월 13일
Roel
2014년 8월 13일
Amir
2014년 8월 14일
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
2014년 8월 14일
Amir
2014년 8월 14일
I hope the attached files help you Roel.
카테고리
도움말 센터 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!