facing problem in reshaping the column matrix please help
Show older comments
clc;
close all;
clear all;
printlevel=3;
n=input('n=');
for kk = 0:n
for ii = 0:n
for jj = 0:n
E = ((nchoosek(n,ii))/(2*n+kk+1))*((nchoosek(n,jj))/(nchoosek(2*n+kk,ii+kk+jj)))
end
ee(kk+1,ii+1) = reshape(E,n+1,1)
end
end
Answers (1)
Maybe you mean:
n = 3;
E = zeros(n+1, 1); % Pre-allocate in wanted dimension instead of reshape
ee = zeros(n+1, n+1, n+1); % Preallocate!
for kk = 0:n
for ii = 0:n
for jj = 0:n
E(jj + 1) = (nchoosek(n,ii) / (2*n+kk+1)) * ...
(nchoosek(n,jj) / nchoosek(2*n+kk, ii+kk+jj));
% ^^^^^^^^
end
ee(kk+1, ii+1, :) = E;
% ^ E is a vector, you cannot assign it to the
% scalar ee(kk+1,ii+1)
end
end
ee
1 Comment
Faheem Khan
on 5 Mar 2022
Categories
Find more on Matrices and Arrays 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!