필터 지우기
필터 지우기

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