more non-singleton rhs dimensions

I am getting an error here but I am not sure why.
I am trying to create a 1x5 matrix for the 5 c answers using the 5 t values in that matrix.
Thanks

4 comentarios

Jon
Jon el 26 de Oct. de 2020
Your screen shot shows some licensing page.
In any case please explain your question in words rather than a screen shot. The code button on the MATLAB answers toolbar allows you to paste in code and have it nicely formatted as in the MATLAB editor
Matthew Gilroy
Matthew Gilroy el 26 de Oct. de 2020
Sorry I attatched the wrong screenshot this is the correct one
Thanks
Star Strider
Star Strider el 26 de Oct. de 2020
Copy and past the actual code rather than an image of it, then highlight all of it and use the ‘Insert a line of code’ button to format it cortrectly.
x = (0:1:100)'; 'metres'
Ex = 0.02; 'm^2/s'
m = 1;
u = 0.5; 'm/s'
c = zeros(1,5);
t = [30, 60, 90, 120, 150];
for t = (1:5)
c(1,t) = (m ./ (sqrt(4.*pi.*Ex.*t))).* exp(-((x - u.*t).^2)./(4.*Ex.*t));
end

Iniciar sesión para comentar.

 Respuesta aceptada

Jon
Jon el 26 de Oct. de 2020
I'm thinking that you want to loop through your t values. You first assign t to the vector [30,60,90,120,150] but then reassign it in your for loop to (1:5) or [1 2 3 4 5]. You instead need to index your values of t inside of your loop something like
x = (0:1:100)'
Ex = 0.02
m = 1
u = 0.5
c = zeros(101,5)
t = [30,60,90,120,150];
for k = 1:5
c(:,k) = m/sqrt(4*pi*Ex*t(k))*exp(-(x-u*t(k)).^2)./(4*Ex*t(k))
end

2 comentarios

Jon
Jon el 26 de Oct. de 2020
Note that the ".*" are only needed for element by element multiplication. You don't need that when you multiply scalars times vectors. Also I think you were trying to put in comments for the units. To do that you need to proceed them with a % sign e.g
Ex = 0.02; % m^2/s
Matthew Gilroy
Matthew Gilroy el 26 de Oct. de 2020
Cheers this has worked thanks for the help.

Iniciar sesión para comentar.

Más respuestas (1)

Matthew Gilroy
Matthew Gilroy el 26 de Oct. de 2020

0 votos

Sorry I attatched the wrong screenshot this is the correct one
Thanks

Categorías

Etiquetas

Preguntada:

el 26 de Oct. de 2020

Comentada:

el 26 de Oct. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by