how to multiply 2 matrix A of dimension 5*4 and matrix B of dimension 4*1 upto k times?

1 vue (au cours des 30 derniers jours)
this is the code we tried .But we are not getting appropriate output
clc;
clear all;
m=5;
n=4;
k=3;
x=2*randint(n,1)-1;
p=rand(m,n,k);
y(m,1,k)=p(m,n,k).*x(n,1);
  3 commentaires
PLACEIUS NISHIGA G
PLACEIUS NISHIGA G le 27 Fév 2018
we are getting wrong outputs.Could you suggest a solution for this.

Connectez-vous pour commenter.

Réponse acceptée

Birdman
Birdman le 27 Fév 2018
Firstly, x variable here is not 4x1 and also .* means elementwise multiplcation but you want to do matrix multiplication, therefore use the following code(Note that whatever your size is, which is k in this case, the matrices are going to be multiplied):
m=5;n=4;k=3;
x=2*randi(n,[n 1])-1
p=rand(m,n,k)
p2D=reshape(permute(p,[1 3 2]),[],size(p,2));
y=reshape(p2D*x,size(p,1),[],size(p,3))

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 27 Fév 2018
m=5;
n=4;
k=3;
x = 2*(rand(n,1) > .5) - 1;
p = rand(m,n,k);
y = squeeze(sum(bsxfun(@times,p,reshape(x,1,[])),2))
  2 commentaires
PLACEIUS NISHIGA G
PLACEIUS NISHIGA G le 27 Fév 2018
The code works only once.Could you suggest by modifying upto K times.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical 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