facing problem in reshaping the column matrix please help

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

Réponses (1)

Jan
Jan le 4 Mar 2022
Modifié(e) : Jan le 4 Mar 2022
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
ee =
ee(:,:,1) = 0.1429 0.0714 0.0286 0.0071 0.0179 0.0179 0.0107 0.0036 0.0040 0.0060 0.0048 0.0020 0.0012 0.0024 0.0024 0.0012 ee(:,:,2) = 0.0714 0.0857 0.0643 0.0286 0.0179 0.0321 0.0321 0.0179 0.0060 0.0143 0.0179 0.0119 0.0024 0.0071 0.0107 0.0083 ee(:,:,3) = 0.0286 0.0643 0.0857 0.0714 0.0107 0.0321 0.0536 0.0536 0.0048 0.0179 0.0357 0.0417 0.0024 0.0107 0.0250 0.0333 ee(:,:,4) = 0.0071 0.0286 0.0714 0.1429 0.0036 0.0179 0.0536 0.1250 0.0020 0.0119 0.0417 0.1111 0.0012 0.0083 0.0333 0.1000

Catégories

En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by