Error:Assignment has more non-singleton rhs dimensions than non-singleton subscripts

3 views (last 30 days)
So I have the following code to find the normal pdf of a given set of means(m) and standard deviations(s). Along with the 5th,25th,75th and 95th percentiles. x is a random variable with upper and lower limit.
x=[2.22594:0.05:2.73436];
m=[2.3890 2.3891 2.3782 2.4211 2.6127 2.7343 2.6273 2.4738 2.3638 2.2791 2.2259 2.2516];
s=[0.0000 0.0000 0.0912 0.1416 0.1906 0.2200 0.2320 0.2378 0.2414 0.2453 0.2525 0.2791];
y=zeros(1,12);
z=zeros(1,12);
for i=1:12
y(1,i)=normpdf(x,m(1,i),s(1,i));
plot(x,y);
hold on
z(1,i)=prctile(y,[5 25 75 95]);
end
The error i am getting is "Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in Math (line 8) y(1,i)=normpdf(x,m(1,i),s(1,i));" Can someone please help me solve this.

Accepted Answer

Walter Roberson
Walter Roberson on 13 Nov 2016
normpdf() generates one output value for each of its X input values. You then try to assign those multiple output values to a single location y(1,i) . You should probably use y(:,i) and the corresponding change to z, after changing the initialization of y to be zeros(length(x),length(m))
  10 Comments
M.Bilal
M.Bilal on 26 Jan 2020
Edited: M.Bilal on 26 Jan 2020
Hey Walter, i have same problem and seeking your help in this regard.
I have a 6x6 matrix, say C_m, (as shown below) in which some entries are zero and all other entries are cloumn vectors (of order 142x1) c11, c12 & c44. eg c11 = [a11,a12,a13...], c12 = [b11,b12,b13...], c13 = [d11,d12,d13...], c44 =[e11,e12,13...].
How do I define all these column vectors in folllowing 6x6 matrix (C_m), so that matlab recognizes it?
And, all i need, is the resultant matrix C_m should be of the order 142x1 matrix.
C_m = [c11 c12 c12 0 0 0
c12 c11 c12 0 0 0
c12 c12 c11 0 0 0
0 0 0 2*c44 0 0
0 0 0 0 2*c44 0
0 0 0 0 0 2*c44]
Following problem occur, when i run the code? how do i solve this?
Error using horzcat
Dimensions of matrices being concatenated are not
consistent.
Error in bilal2 (line 287)
287 C_m = [c11 c12 c12 0 0 0
Walter Roberson
Walter Roberson on 26 Jan 2020
Each of your hardcoded 0 constants need to be replaced by zeros() the same size as your c matrices.
Z = zeros(size(c11));
C_m = [ c11 c12 c12 Z Z Z
c12 c11 c12 Z Z Z
c12 c12 c11 Z Z Z
Z Z Z 2*c44 Z Z
Z Z Z Z 2*c44 Z
Z Z Z Z Z 2*c44]

Sign in to comment.

More Answers (1)

Nikhil Bharadwaj
Nikhil Bharadwaj on 21 Aug 2018
Edited: Walter Roberson on 21 Aug 2018
I have attached the entire matlab file of my code.
  16 Comments
Walter Roberson
Walter Roberson on 27 Aug 2018
I do not understand what you mean about that conversion ?
I am not familiar with locally weighted linear regression. I also do not know much about speech processing.

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!