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