Subscripted assignment dimension mismatch.

7 vues (au cours des 30 derniers jours)
dj
dj le 29 Oct 2018
Hi everyone. I'm new to MATLAB. What i am trying to do with this code is to plot the sum of the n values vs t that has 0.005 time step but i couldnt figure it out and whatever i try i get an subscripted assignment dimension match in l,ne 26(surface(2,k)=n+surface(2,k);). Also i want to see all the results for each variable i created, anybody has suggestions for that too? Here is my code;
clear
clc
d=0.4;
A=0.15;
B=1.6;
fo=0.0005;
e=((2*pi)*rand(1,50)); %epsilon
count=1;
for i=1:50;
for t=0:0.005:300;
f=(1.1^(i-1))*fo; %fi
T=1/f; %ti
k=2*pi/(dispersion(T,d)); %ki
h=0.5*(1+((2*k*d)/sinh(2*k*d))); %ni
ph=(1/(2*h))*(tanh(k*d))^2; %fi
a=abs((0.2*f*(0.205*(A^2)*(B^-4)*(f^-5)*exp(-0.75*(B*(f^-4))*ph)))^0.5); %ai
Ur(count)=2*a*(dispersion(T,d))^2/d^3; %Ursell Number
n(count+1)=a*cos((2*pi*f*t)+e(i)); %n(t)
count=count+1;
end
end
for k=1:3000050;
surface(2,k)=0;
for i=1:50;
surface(1,k)=t;
surface(2,k)=n+surface(2,k);
end
end
plot(surface(1,:),surface(2,:))

Réponse acceptée

Walter Roberson
Walter Roberson le 30 Oct 2018
You assign to n(count+1) so n will be a vector. surface(2,k) is a scalar. When you add vector n to scalar you get a vector result, which cannot be stored back into a scalar location.
I notice that the maximum location stored at for n is exactly one larger than the upper limit of your for k loop. That suggests to me that you want to add n(k+1) instead of the entire n

Plus de réponses (1)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by