Info

此问题已关闭。 请重新打开它进行编辑或回答。

error when reading from xls sheet

1 次查看(过去 30 天)
Ayda
Ayda 2011-10-31
关闭: MATLAB Answer Bot 2021-8-20
Good evening\morning
I have a system of equations and i expressed them in matrix form
R=[ R(3)+R(5)+R(8) , -R(5) , 0 , -R(3);
-R(5), R(1)+R(4)+R(5)+R(7) , -R(4), 0;
0, -R(4) , R(2)+R(4)+R(6) , -R(6);
-R(3) , 0 , -R(6) , R(3)+R(6)+R(9)];
V= [V(1);0;0;V(2)];
I've to do a matrix division and some other things But when I read the voltages values from xls file as
10
0
0
10
it read it Matrix V (in Volts)
10.0
0.0
0.0
0.0
Also when it try to enter the value from the terminal it read it as zero
fid= fopen('mesh.txt','w');
% R=input('inter resistor value in kilo ohms, [R1...R9]= ');
R=xlsread('test');
% V=input('inter voltage value in volt, [V1 V2]= ');
V=xlsread('v');
R=[ R(3)+R(5)+R(8) , -R(5) , 0 , -R(3);
-R(5), R(1)+R(4)+R(5)+R(7) , -R(4), 0;
0, -R(4) , R(2)+R(4)+R(6) , -R(6);
-R(3) , 0 , -R(6) , R(3)+R(6)+R(9)];
V= [V(1);0;0;V(2)];
fprintf(fid,'Matrix R (in Kohms)\n\n');
fprintf(fid,'\t%.1f\t\t %.1f\t\t %.1f\t\t %.1f\t\n\n',R);
fprintf(fid,'Matrix V (in Volts)\n\n');
fprintf(fid,'%.1f\n %.1f\n %.1f\n %.1f\n\n',V);
I=R\V;
fprintf(fid,'Mesh Currents I (in mAmber)\n\n');
fprintf(fid,'%.4f\n %.4f\n %.4f\n %.4f\n\n',I);
inverse= inv(R);
fprintf(fid,'Inverse of R (in Kohms)\n\n');
fprintf(fid,'%.4f\t %.4f\t %.4f\t %.4f\t\n\n',inverse);
I=invers\V;
fprintf(fid,'Mesh Currents I (in mAmber)\n\n');
fprintf(fid,'%.4f\n %.4f\n %.4f\n %.4f\n',I);
fclose(fid);
  1 个评论
bym
bym 2011-10-31
I think you have a number of typographical errors (typos) in your code; plus formatting it using the {}Code button would help readability and increase the probability someone would provide the answer you seek

回答(1 个)

Ken Atwell
Ken Atwell 2011-11-2
If the file 'v' contains '10;0;0;10', the statement:
V= [V(1);0;0;V(2)];
two lines later would reset V to '10;0;0;0' as you are observing. Do you mean:
V = [V(1); V(4)];

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by