필터 지우기
필터 지우기

"when i used Matlab function i got the error message" Colon operands must be all the same type, or mixed with real scalar doubles.

조회 수: 20 (최근 30일)
Hello there !
This is my text.xlxs file
function Voltage = fcn(~)
coder.extrinsic('xlsread')
current =3;
Signal=xlsread('test.xlsx'); % read from file
frq= size(Signal,1);
S12= size(Signal,2);
for i=1 :Signal
if (frq(i) == 2.4500 )
x=S12(i);
end
end
Power= x^2;
Voltage = Power/current;
end
It's keep show me this error when i run it " Colon operands must be all the same type, or mixed with real scalar doubles."
Actually I'm just a beginner in Matlab, So can you tell me please how can I fix it?
  댓글 수: 2
Subhadeep Koley
Subhadeep Koley 2020년 5월 10일
Hi, can you share your test.xlsx file? A first observation reveals that your definition of the indexing variable range i is not correct. The variable Signal is most probably a 2d matrix. Therefore you can not vary i from 1 to Signal.
Walter Roberson
Walter Roberson 2020년 5월 10일
notice that frq is a scalar double, but you are going to try to index it. You need to rethink your indexing

댓글을 달려면 로그인하십시오.

답변 (1개)

Ayush Goyal
Ayush Goyal 2020년 6월 19일
From my understanding of the question you are facing issue while extracting columns of Signal matrix into separate vectors as frq and S12. You can refer to the following link for how to extract columns of a matrix into separate vectors:
Also, iterate your for loop from 1 to number of rows in Signal Matrix. Check the following code:
function Voltage = fcn(~)
coder.extrinsic('xlsread')
current =3;
Signal=xlsread('test.xlsx'); % read from file
frq= Signal(:,1); % Extract first column of Signal
S12= Signal(:,2); % Extract second column of Signal
for i=1:size(Signal,1) %Iterate upto number of rows in Signal
if (frq(i) == 2.4500 )
x=S12(i);
end
end
Power= x^2;
Voltage = Power/current;
end

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by