필터 지우기
필터 지우기

Simplifying a code to one matrix

조회 수: 1 (최근 30일)
Mahmoud Abbas
Mahmoud Abbas 2022년 3월 13일
댓글: Mahmoud Abbas 2022년 3월 15일
%I want to make this code perform the same function but using a matrix M(x,y) instead of using 2 variables
%meaning I want the code to return the final values of Mx and My in a single 1x2 Matrix
function [Mx,My]=fun(P,n,p,u,U)
S= span(n,p,u,U);
Z= Bas(S,u,p,U);
Mx=0; My=0;
for k=1:p+1
Mx= Mx + Z(k) * P(1, S-(p+1)+k);
My= My + Z(k) * P(2, S-(p+1)+k);
end
end

채택된 답변

Arif Hoq
Arif Hoq 2022년 3월 13일
you can concatenate the matrix Mx and My either horizontally or vertically
% if horizontal
output=horzcat(Mx,My)
% if vertical
output=vertcat(Mx,My)
  댓글 수: 2
Arif Hoq
Arif Hoq 2022년 3월 15일
@Mahmoud Abbas did my answer solve your problem ?
Mahmoud Abbas
Mahmoud Abbas 2022년 3월 15일
Ah yes, all great!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by