The following data will be used in this question set Create

The following data will be used in this question set. Create the variable Comp as a cell array, containing the component names shown in Column 1. Create the variable CurData as single matrix containing the information shown in Columns 3 - 7. The first row is the voltage in units of volts and the subsequent rows are the current corresponding to their respective components in units of millamperes. Ask the user to choose a material from a menu created using the names stored in Choice. Display for the user the choice of voltages given in row 1 of CurData in a menu. Not there is one tab between numerical values. Show the following information in the command window, using the component and voltage chosen above and the corresponding current found in the matrix CruData. If the input to the questions above is charged, the shown in the output should change accordingly.

Solution

Call challenge2() from console

Program
function challenge2()
Comp = {\'Holtz100\',\'Lever014\',\'Dillard202\'};
draw(Comp)
end

function draw(Comp)
compFig=figure(\'Position\',[200 200 1600 600]);
for i=1:length(Comp)
tb = uicontrol(compFig,\'Style\',\'pushbutton\',\'String\',Comp{1,i},\'Value\',0,\'Position\',[30 60*(length(Comp)-i) 100 30],\'Callback\',{@compCallback,Comp,i});
end
end

function compCallback(src,event,Comp,indexComp)
CurData = [5 7 10 12 15;128 142 165 180 212;18 20 23 25 30;260 285 333 368 428];
volts = CurData(1,:);
voltFig=figure(\'Position\',[200 200 1600 600]);
for i=1:length(volts)
    tb = uicontrol(voltFig,\'Style\',\'pushbutton\',\'String\',num2str(volts(1,i)),\'Value\',0,\'Position\',[30 60*(length(volts)-i) 100 30],\'Callback\',{@voltCallback,indexComp,i,CurData,Comp});
end
end

function voltCallback(src,event,indexComp,indexVolt,CurData,Comp)
DISP = sprintf(\'Component %s\ Voltage = %d V; Current = %d mA\',Comp{1:indexComp},CurData(1,indexVolt),CurData(1+indexComp,indexVolt));
disp(DISP)
end

 The following data will be used in this question set. Create the variable Comp as a cell array, containing the component names shown in Column 1. Create the va

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site