User input not being plugged into the equation
Show older comments
Hello,
Something tells me there's a simple solution to my problem, but i can't seem to figure it out. Here's my code:
prompt={'Enter value for R_bd: ', 'Enter value for R_ad: ', 'Enter value for R_ae: ', 'Enter value for R_be: '};
answer=inputdlg(prompt);
x1 = str2num(answer{1});
x2 = str2num(answer{2});
x3 = str2num(answer{3});
x4 = str2num(answer{4});
equ1='x1-R1*(R2+R3+R4)/(R1+R2+R3+R4)';
equ2='x2-R2*(R1+R3+R4)/(R1+R2+R3+R4)';
equ3='x3-R3*(R1+R2+R4)/(R1+R2+R3+R4)';
equ4='x4-R4*(R1+R2+R3)/(R1+R2+R3+R4)';
sol=solve(equ1,equ2,equ3,equ4);
R1=sol.R1
R2=sol.R2
R3=sol.R3
R4=sol.R4
My issue with this code is, the number being entered by the user (say you input 3 for all the four answers) is not being plugged in equ1 - equ4 to generate an answer.
When I write the code like this it works just fine:
equ1='3-R1*(R2+R3+R4)/(R1+R2+R3+R4)';
equ2='3-R2*(R1+R3+R4)/(R1+R2+R3+R4)';
equ3='3-R3*(R1+R2+R4)/(R1+R2+R3+R4)';
equ4='3-R4*(R1+R2+R3)/(R1+R2+R3+R4)';
sol=solve(equ1,equ2,equ3,equ4)
R1=sol.R1
R2=sol.R2
R3=sol.R3
R4=sol.R4
But the values can vary which is why I need the user to input the values. What am I doing wrong?
Thank you in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!