- You can't use size() to extract things from an array. Replace frq= size(Signal,1); with frq = Signal(:,1);
- You can't use an array as an index (this is the cause of the error message since Signal will be an array after reading the data from your spreadsheet). Use, for example, for i = 1:numel(frq).
"Colon operands must be all the same type, or mixed with real scalar doubles" error I'm trying to run excel file into Matlab function
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello there! I'm trying to run excel file using Matlab function but this error keep appears to me "Colon operands must be all the same type, or mixed with real scalar doubles".Can someone help me to fix it !!
This is my Excel file
test.xlxs
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/291926/image.jpeg)
By using this code
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 %%%%% Colon operands must be all the same type, or mixed with real scalar doubles
if (frq(i) == 2.4500 )
x=S12(i);
end
end
Power= x^2;
Voltage = Power/current;
end
0 comentarios
Respuestas (1)
Les Beckham
el 10 de Mayo de 2020
Well there are several things wrong with this code.
Also, though not wrong, there is an easier way to find your 'x' without using a loop: x = S12(frq==2.45)
If you are planning to use this in a Simulink Matlab function block (I'm just guessing based on the coder.extrinsic call), I would recommend against repeatedly calling xlsread in a Simulink simulation unless, for some strange reason, you expect text.xlsx to be changing during the simulation run.
There is probably a better way to achieve what you are trying to do. If you explain what you are trying to do you may get some suggestions on how to do it more effectively.
0 comentarios
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!