How to replace certain values in an existing array based off of inputdlg?

3 ビュー (過去 30 日間)
Roel
Roel 2014 年 8 月 13 日
コメント済み: Amir 2014 年 8 月 14 日
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?

採用された回答

Amir
Amir 2014 年 8 月 13 日
編集済み: Amir 2014 年 8 月 13 日
Hi Roel. Try this code:
Rsh = str2num(char(answer{1}));
Rs = str2num(char(answer{2}));
Isc = str2num(char(answer{3}));
Voc = str2num(char(answer{4}));
n = str2num(char(answer{5}));
index=str2num(char(answer{6}));
and then look at the attached files below (a simple example which shows how you can pass your data in GUI).
Hope this helps.
  1 件のコメント
Roel
Roel 2014 年 8 月 13 日
This helps so much! I was struggling to save things to a variable for use later. Thanks!

サインインしてコメントする。

その他の回答 (1 件)

Joseph Cheng
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
Roel 2014 年 8 月 14 日
I am not quite certain on the static texts corresponding to a radio button. Can I make a radio button appear on an input dlg? Or rather, can I call this GUI from my Main GUI? In other words can I run one GUI, then upon some callback, a new one will open?
Amir
Amir 2014 年 8 月 14 日
I hope the attached files help you Roel.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by