multiplication table in matlab

130 vues (au cours des 30 derniers jours)
mohamed
mohamed le 1 Mar 2013
Réponse apportée : Akmal le 19 Juin 2022
I want to make the multiplication table using matlab ?
  2 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 1 Mar 2013
What does that mean?
leela krishna
leela krishna le 30 Juin 2019
the output is the multiplication table of any number
clc;
clear all;
n=input('Enter an integer:');
i=1;
while(i<=10)
fprintf('%d*%d=%d \n',n,i,n*i);
i=i+1;
end

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 1 Mar 2013
Modifié(e) : Azzi Abdelmalek le 1 Mar 2013
x=(1:9)'
a=repmat(x,1,9)
b=a'
c=bsxfun(@times,x,x')
out=arrayfun(@(x,y,z) [num2str(x) 'x' num2str(y) '=' num2str(z)],a,b,c,'un',0)
  3 commentaires
mohamed
mohamed le 10 Mar 2013
Modifié(e) : mohamed le 10 Mar 2013
i can't understand how arrayfun operates ?
Azzi Abdelmalek
Azzi Abdelmalek le 10 Mar 2013
Modifié(e) : Azzi Abdelmalek le 10 Mar 2013
Look at this example:
a=[2 4 8]
%I want to do some operation to each number of a
out(1)=a(1)*100+cos(a(1))
out(2)=a(2)*100+cos(a(2))
out(3)=a(3)*100+cos(a(3))
%This can be done with arrayfun
out=arrayfun(@(x) x*100+cos(x),a)

Connectez-vous pour commenter.

Plus de réponses (4)

John Doe
John Doe le 22 Mai 2013
Another one-liner:
cumsum(meshgrid(1:10))

Teja Muppirala
Teja Muppirala le 23 Mai 2013
N = 10
(1:N)'*(1:N)
  2 commentaires
Morganne Durham
Morganne Durham le 22 Jan 2018
To make a matrix for a times table, you need to use a period before the *
(1:N)'.*(1:N)
Matt J
Matt J le 22 Jan 2018
Modifié(e) : Matt J le 22 Jan 2018
No, you don't need .*
Also, the latter will only work in R2016b and higher. This thread was from back in 2013.

Connectez-vous pour commenter.


Matt J
Matt J le 1 Mar 2013
As an example, This will generate a times table for integers 1...10
bsxfun(@times, (1:10).',1:10)

Akmal
Akmal le 19 Juin 2022
...

Catégories

En savoir plus sur Matrices and Arrays 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