I want to make the multiplication table using matlab ?

2 Kommentare

Azzi Abdelmalek
Azzi Abdelmalek am 1 Mär. 2013
What does that mean?
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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 1 Mär. 2013
Bearbeitet: Azzi Abdelmalek am 1 Mär. 2013

3 Stimmen

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 Kommentare

You can add a table
f = figure('Position',[100 100 800 250]);
uitable('Units','normalized','Position',[0.1 0.1 0.9 0.9],'data',out)
mohamed
mohamed am 10 Mär. 2013
Bearbeitet: mohamed am 10 Mär. 2013
i can't understand how arrayfun operates ?
Azzi Abdelmalek
Azzi Abdelmalek am 10 Mär. 2013
Bearbeitet: Azzi Abdelmalek am 10 Mär. 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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

John Doe
John Doe am 22 Mai 2013

4 Stimmen

Another one-liner:
cumsum(meshgrid(1:10))
Teja Muppirala
Teja Muppirala am 23 Mai 2013

4 Stimmen

N = 10
(1:N)'*(1:N)

2 Kommentare

To make a matrix for a times table, you need to use a period before the *
(1:N)'.*(1:N)
Matt J
Matt J am 22 Jan. 2018
Bearbeitet: Matt J am 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.

Melden Sie sich an, um zu kommentieren.

Matt J
Matt J am 1 Mär. 2013

3 Stimmen

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

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 1 Mär. 2013

Beantwortet:

am 19 Jun. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by