multiplication table in matlab

125 ビュー (過去 30 日間)
mohamed
mohamed 2013 年 3 月 1 日
回答済み: Akmal 2022 年 6 月 19 日
I want to make the multiplication table using matlab ?
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 1 日
What does that mean?
leela krishna
leela krishna 2019 年 6 月 30 日
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

サインインしてコメントする。

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 1 日
編集済み: Azzi Abdelmalek 2013 年 3 月 1 日
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 件のコメント
mohamed
mohamed 2013 年 3 月 10 日
編集済み: mohamed 2013 年 3 月 10 日
i can't understand how arrayfun operates ?
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 10 日
編集済み: Azzi Abdelmalek 2013 年 3 月 10 日
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)

サインインしてコメントする。

その他の回答 (4 件)

John Doe
John Doe 2013 年 5 月 22 日
Another one-liner:
cumsum(meshgrid(1:10))

Teja Muppirala
Teja Muppirala 2013 年 5 月 23 日
N = 10
(1:N)'*(1:N)
  2 件のコメント
Morganne Durham
Morganne Durham 2018 年 1 月 22 日
To make a matrix for a times table, you need to use a period before the *
(1:N)'.*(1:N)
Matt J
Matt J 2018 年 1 月 22 日
編集済み: Matt J 2018 年 1 月 22 日
No, you don't need .*
Also, the latter will only work in R2016b and higher. This thread was from back in 2013.

サインインしてコメントする。


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

Akmal
Akmal 2022 年 6 月 19 日
...

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by