Error using / Matrix dimensions must agree...

565 次查看(过去 30 天)
Below is my script:
>> clf
>> hold on
>> axis([-1 1 -1 1])
>> x=-1:0.0001:1;
>> y=cos(1/x)
>> plot(x,y)
May I know why I keep getting this error:-
(Error using / Matrix dimensions must agree...)?
  1 个评论
guadalupe presa
guadalupe presa 2016-9-22
kEST=(s/(n+g+d))^(1/(1-alfa)); % realiza un código (k*)=steady state (NIVEL DE CAPITAL DE EQUILIBRIO)
SteadyState=findobj('Tag','STEADYSTATE'); set(SteadyState,'String',kEST);
upper=ceil(kEST)*2; jump=upper/10; k=(0:jump:upper)';
ec1=(n+g+d).*k; %ecuación 1= capital consumido: (n+g+d)*k (RECTA - FUNCION DE PRODUCCION) ec2=s.*k.^alfa; %ecuación 2= de capital acumulados:s*k^alfa (CURVA - FUNCION DE INVERSIÓN)
error: Error using / Matrix dimensions must agree.
Error in MODELOSOLOWCURVASFASE (line 87) kEST=(s/(n+g+d))^(1/(1-alfa)); % realiza un código (k*)=steady state (NIVEL DE CAPITAL DE EQUILIBRIO)

请先登录,再进行评论。

采纳的回答

Amit Nambiar
Amit Nambiar 2013-10-2
It should be like this: >> clf >> hold on >> axis([-1 1 -1 1]) >> x=-1:0.0001:1; >> y=cos(1./x) >> plot(x,y)
always use .* ./ (mul and div resp)for element by element operations. And use * / without "." for matrix operations.

更多回答(6 个)

Matt J
Matt J 2013-10-2

Image Analyst
Image Analyst 2013-10-2

Mugisha Aime
Mugisha Aime 2017-9-21
Matrix dimensions must agree.
  3 个评论
Muhammad Azrul Izmee
This is not right too.. I hv do it but keep getting error
Image Analyst
Image Analyst 2022-1-27
@Muhammad Azrul Izmee, it is right. Here's proof
x=-1:0.0001:1;
y=cos(1 ./ x)
y = 1×20001
0.5403 0.5402 0.5401 0.5400 0.5400 0.5399 0.5398 0.5397 0.5396 0.5395 0.5395 0.5394 0.5393 0.5392 0.5391 0.5390 0.5390 0.5389 0.5388 0.5387 0.5386 0.5385 0.5384 0.5384 0.5383 0.5382 0.5381 0.5380 0.5379 0.5379
plot(x, y, 'b-')
See? No error.
You should start a new question with your own code.

请先登录,再进行评论。


moahaimen talib
moahaimen talib 2017-3-20
hi please i need your help i need to process many images into wavelet function
yFolder = 'images';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
figure(k);imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
[coeffa,coeffh,coeffv,coeffd]=wavelet_process(imageArray);
i recieve this error
Error using + Matrix dimensions must agree.
Error in idwt2 (line 89) x = upsconv2(a,{Lo_R,Lo_R},sx,dwtEXTM,shift)+ ... % Approximation.
Error in wavelet_inv_process (line 5) resimg=idwt2(coeffa,coeffh,coeffv,coeffd,'haar');
Error in top_run2 (line 74) inv_wave_img=wavelet_inv_process(coeffa,imgadjh,imgadjv,imgadjd);
please SOS

ahmed reda
ahmed reda 2019-7-3
编辑:Image Analyst 2019-7-3
i want to know the error of this code iwant to plot w with X&Y and this error is founed
clear ;
clc;
close all;
R=0.01; %Shaft radius
m=1.675; %Disc mass (Kg)
L=0.5; %Shaft Length (m)
E=210*10^9; %Modulus of elasticity (N/m^2)
Ro=7850; %Density (Kg/m^3)
Ix=(1/4)*pi*R^4; %Moment of Inertia (Kg.m^2)
A=pi*R^2; %Cross section area (m^2)
K=48*E*Ix/L^3; %Shaft Stiffness simply supported (N/m)
Z=0.00125; %Damping ratio
C=Z*2*sqrt(K*m); %Damping constant (N/m)
e=0.059665; %eccentricity (m)
N=1500; %(rpm)
w=(0:.5:30); %rotational speed (rad/sec)
Wn=sqrt(K/m); % natural frequency
% h=0.001; %time step (sec)
g=9.81;
O=m*g/K; %Initial deflection
T=5;fs=5*8*w/(2*pi); dt=1/fs; %sampling frequency
tspan=(0:dt:T); %time interval
% X0 = [0 0]; %Initial displacement, Initial velocity in X direction
% Y0 = [O 0]; %Initial displacement, Initial velocity in y direction
% [~,X]=ode45(@abdo,tspan,X0,[],m,K,C,w,e);
% [t,Y]=ode45(@reda,tspan,Y0,[],m,K,C,w,e);
X=(m*e*(w*w))/sqrt((K-m*(w*w))^2+(C*w)^2);
Y=(m*e*(w*w))/sqrt((K-m*(w*w))^2+(C*w)^2);
plot(w,X);grid;xlabel('W(rad/sec)');ylabel('X');
figure
plot(w,Y);grid;xlabel('W(rad/sec)');ylabel('Y');
The error is:
Error using /
Matrix dimensions must agree.
Error in amplitudewithfrequency (line 21)
T=5;fs=5*8*w/(2*pi); dt=1/fs; %sampling frequency
  5 个评论
Rafli Noorsyaif
Rafli Noorsyaif 2021-1-17
clc
clear all
close all
%Diketahui (E1,E2,G12 dalam satuan MPa)
E = 180000;
SIGMAY = 502;
%S,A,W dalam satuan m
S = 0.1;
a = 0.005;
W = 0.01:0.01:0.1;
K = ((3*(S/W)*sqrt(a/W))/(2*(1+2*(a/W))*((1-(a/W))^(3/2))))*(1.99-(a/W)*(1-(a/W)))*(2.15-3.93*(a/W)+2.7*((a/W)^(2)))
Displacement = (K^(2))/(E*SIGMAY)
I have the same problem (Matrix dimensions must agree) on the line 14
K = ((3*(S/W)*sqrt(a/W))/(2*(1+2*(a/W))*((1-(a/W))^(3/2))))*(1.99-(a/W)*(1-(a/W)))*(2.15-3.93*(a/W)+2.7*((a/W)^(2)))
Image Analyst
Image Analyst 2021-1-17
Rafli, usually what many/most people do in situations like this, which have an incredibly complicated and involved equation, is to break it down into smaller parts, then examine the size of each term. Like
term1 = 3*S/W;
term2 = sqrt(a/W);
and so on. Just basic debugging technique.
Then make sure all your matrix multiplication dimensionss of each term make sense, and also make sure you really want to do a matrix multiplication with star and not an element-by-element multipliication with dot star.For example since you have term1*term2, that means the number of columns in term1 must equal the number of rows in term1 for a matrix multiplication since term1 is on the left side.
Start your own question if you still have trouble.

请先登录,再进行评论。


Rahayu A Halim
Rahayu A Halim 2021-8-8
Hello, please I need your help
my script:
%____________________________________________________________________
function fx=obj_pid_ga(x)
global Kp Ki Kd
%
%
Kp=x(1);Ki=x(2);Kd=x(3);
%
%____________________________________________________________________
[t,~,y]=sim('model_sistem_PID',0:0.05:10);
%____________________________________________________________________
%Integral of Squared Error
fx=sum(t.*abs(y).^2);
May I know why I keep getting this error:
Error using .*
Matrix dimensions must agree.
Error in obj_pid_ga (line 10)
fx=sum(t.*abs(y).^2);

类别

Help CenterFile Exchange 中查找有关 Biological and Health Sciences 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by