Anyone please do this on matlab

Create a function whose name should be your own name. This function would take 3 vectors of different sizesas input.The output of the function should be the same 3 vectors arrangedin ascending order according to their sizes. The function should also return another vector which is sum of all 3vectors.

1 件のコメント

the cyclist
the cyclist 2021 年 6 月 26 日
This certainly looks like a homework assignment. Post what you have tried, and we may help you along.
If you don't have any experience with MATLAB, try the MATLAB Onramp tutorial.

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

回答 (1 件)

Soniya Jain
Soniya Jain 2021 年 6 月 26 日

0 投票

x = 1:2;
y = 1:3;
z = 1:4;
% a1, a2, a3 are 3 vectors arranged in ascending order
% let's pass x,y and z in jumbled order
[a1, a2, a3, sum] = solve(y,z,x);
function [a1, a2, a3, sum] = solve(a,b,c)
[x1,s1]=size(a);
[x2,s2]=size(b);
[x3,s3]=size(c);
sum = 0;
if(s1 > s2 && s1 > s3)
a1 = a;
if(s2 > s3)
a2 = b;
a3 = c;
else
a2 = c;
a3 = b;
end
elseif(s2 > s3 && s2 > s1)
a1 = b;
if(s1 > s3)
a2 = a;
a3 = c;
else
a2 = c;
a3 = a;
end
else
a1 = c;
if(s1 > s2)
a2 = a;
a3 = b;
else
a2 = b;
a3 = a;
end
end
% now find sum of all the vector elements
for i = 1:s1
sum = sum + a(i);
end
for i = 1:s2
sum = sum + b(i);
end
for i = 1:s3
sum = sum + c(i);
end
end

4 件のコメント

the cyclist
the cyclist 2021 年 6 月 26 日
@Soniya Jain, I am disappointed that a member of the MATLAB staff would simply answer a homework question for a student.
Star Strider
Star Strider 2021 年 6 月 26 日
@the cyclist — I completely agree!
Image Analyst
Image Analyst 2021 年 6 月 26 日
Well it's not completely solved. @Mr A still has to rename the function from solve() to MrA(). And change the name of the badly-named sum variable to something that's not a built-in function, like theSum.
the cyclist
the cyclist 2021 年 6 月 26 日
Maybe MrA's name is actually "solve".

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

タグ

質問済み:

2021 年 6 月 26 日

コメント済み:

2021 年 6 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by