如何更改数组中的值(MATLAB GUIDE GUI)

时间:2014-08-11 20:31:57

标签: arrays matlab user-interface

我想知道为了根据位置更改数组中的值,函数会是什么样子。在我附加的脚本中,我使用我编写的函数生成电压和电流数组并绘制这些值以便给出我的IV曲线。但是,inputdlg功能尚未使用。我想使用inputdlg框重新运行计算I和V的函数,然后我将用这些新值替换第一个数组中的值并绘制更改。我想知道的是如何在对话框上单击“确定”并使用来自用户指定位置的函数的输出值替换现有数组中的值来执行某些功能。

这是我开始的地方:所有这些输入都来自GUI中的编辑框

function plot_button_Callback(hObject, eventdata, handles)
% hObject    handle to plot_button
% Get user input from GUI
NumS = str2double(get(handles.NumSeries_input,'String'));
%number of cells in series
NumP = str2double(get(handles.NumParallel_input,'String'));
%number of cells in parallel
Rs = eval(get(handles.Rseries_input,'String'));%Series resistance (Ohm)
Rsh = eval(get(handles.Rshunt_input,'String')); %Shunt resistance (Ohm)
Isc = eval(get(handles.Isc_input,'String')); %Short circuit current (A)
Voc = eval(get(handles.Voc_input,'String')); %Open circuit voltage (V)
n = eval(get(handles.n_input,'String')); %Ideality factor 
% Calculate data

这里我打开一个对话框以设置新单元格的参数

headers ={'Param1' 'Param2' 'Param3' 'Param4' 'Param5' 'Location'};
dlg_title = 'Input';
num_lines = 1;
def = round(rand(1,6)*20);
def = def';
def = num2str(def);
deff = cellstr(def);
answer = inputdlg(headers, dlg_title, num_lines, deff);
%Constants
%Parameters

CalculationIVRsRsh定义在我的代码中的其他位置

T=-140; %Temperature in degree C

%Constantes
q=1.602176565e-19; %Charge elementaire (C)
k=1.3806488e-23; %Boltzmann constant (J/K)

%Size of the cell
[garb, taille]=size(Isc);
%Calculation of each cell characteristics
for ind=1:taille
[I(:,ind), V(:,ind)]=CalculationIVRsRsh(Isc(ind),Voc(ind),T,n(ind),Rs(ind),Rsh(ind));
end

这里我根据并行的单元格数复制Current(I)数组

%Combination of the 3 solar cells
Isc3=min(Isc);
IscTm=repmat(Isc',1,NumP); %replicates the input vector for the Isc
%according to how many of the cells in the array are in parallel
IscT=sum(IscTm,2); %sums the Isc for the array
Isc4=min(IscT);  %takes the current limitting value
Iint=-Isc3/20:0.01:min(Isc3);
IintP1=repmat(Iint,NumP,1); %replicates the values for Iint for the IV curve
IintP=sum(IintP1,1); %adds the IintP1 values to simulate the adding currents

for ind=1:taille
Vint(:,ind)=interp1(I(:,ind),V(:,ind),Iint);
IscN(ind)=interp1(V(:,ind),I(:,ind),0);
end
%We are doing the sum of V starting from the lowest I, therefore the 2
%other cells are already at a positive voltage for which the sum is the
%minimum value we can obtain for the 3 junction cell

这里我根据串联的细胞数量复制电压阵列

Isc3=min(IscN);
V3=sum(Vint,2);
Vs=repmat(V3,1,NumS);
V4=sum(Vs,2);

Voc3=sum(Voc);
VocT=NumS.*Voc3;

然后我绘制新数据

%plots data
V3=cat(1,V3,0);
I3=cat(1,Iint',Isc3);
I4=cat(1,IintP',Isc4);
V4=cat(1,V4,0);
plot(V3,I3,V4,I4)
axis([0 VocT+VocT/20 0 max(IscT)+max(IscT)/20]);
xlabel('V (V)');
ylabel('I (A)');
legend('Cell', 'Array');

0 个答案:

没有答案