if true
% code
end
clear
clc
lg=0.0005;
ls=0.0005;
i=2.3;
N=1300;
g=0.002;
g1=linspace(0.002,0.0001,0.0225);
h=0.5;
r=0.2;
nuo=4*pi*10e-7;
B=nuo*N*i/(g1+r*g/(2*h));
Hi i have this code and i got the error 'Matrix dimensions must agree.' I am making a noobly mistake for sure but i am a beginner. How can i fix that? After doing the calculations i need to plot(B,g1). Thank you for your help.

4 comentarios

Alfonso
Alfonso el 10 de Mayo de 2018
What is g1 supposed to be?
Bob Thompson
Bob Thompson el 10 de Mayo de 2018
Editada: Bob Thompson el 10 de Mayo de 2018
g1 is a rather large array, but everything else in B is a single numeric. I'm fairly certain you cannot divide a numeric by an array.
Alfonso
Alfonso el 10 de Mayo de 2018
Editada: Alfonso el 10 de Mayo de 2018
But which values must g1 have? 100 values between 0.002 and 0.0225 for example? I mean g1 as it is defined, is going to give an empty array...
Alican Kahraman
Alican Kahraman el 10 de Mayo de 2018
Editada: Alican Kahraman el 10 de Mayo de 2018
I had a mistake over there. I have thought the second input means difference between the values. I have changed it as below;
linspace(0.002,0.0225,1000)

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 10 de Mayo de 2018

1 voto

Two problems:
1. Your ‘g1’ vector is empty. The length (optional third argument) to linspace must be an integer greater than 0. Any other values return an empty array.
2. You need to vectorise the first division (change / to ./) in your ‘B’ assignment:
B = nuo*N*i./(g1+r*g/(2*h));

2 comentarios

Alican Kahraman
Alican Kahraman el 10 de Mayo de 2018
Thank you!
I have solved the problem.
Star Strider
Star Strider el 10 de Mayo de 2018
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Mayo de 2018

Comentada:

el 10 de Mayo de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by