Is it possible to return a Matrix from a single Set in Matlab?

조회 수: 1 (최근 30일)
Bob
Bob 2014년 3월 15일
편집: Walter Roberson 2014년 3월 15일
Hi, I recently wrote a code that looks like this:
function DataSet = Project(SetA, SetB, SetC)
DataSet = find(SetA, SetB, SetC);
function DataSet = find(SetA, SetB, SetC)
Data1 = SetA - SetB;
Data2 = SetB - SetC;
Data3 = SetC - SetA;
DataSet = [Data1, Data2, Data3];
end
end
The output looks like this when I input in the command:
DataSet = find(1,2,3)
DataSet = -1
If I insert 3 variables such as [Data1, Data2, Data3] = find(1,2,3)
I would get
Data1 = -1
Data2 = -1
Data3 = -2
which is correct. Is it possible, if so how could I change the code so that it output DataSet as a Matrix instead of just 1 value, because if there's suppose 100 variables, I would not want to manually insert 100 variables.
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 3월 15일
Yikes! Do not name your own routine "find" ! That is going to confuse the heck out of programmers who are going to think of the MATLAB find() call!

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

채택된 답변

Walter Roberson
Walter Roberson 2014년 3월 15일
The routine "find" that you define is contained within "Project" and is not available from the command line unless you are at a breakpoint within "Project". Instead you would get MATLAB's find() routine.
  댓글 수: 7
Bob
Bob 2014년 3월 15일
편집: Walter Roberson 2014년 3월 15일
Yes, I fixed it, its still output the incorrect version:
function [Force, Motion] = setVar(Mass, Acceleration, Radius, time)
Force = Mass * Acceleration;
Motion = speedData(Force, time, Radius, Mass)
function Motion = speedData(Force, time, Radius, Mass)
Velocity = 2 * Force * time / Mass;
AngularV = Velocity / Radius
Motion = [Velocity, AngularV];
end
end
Bob
Bob 2014년 3월 15일
Oh, I made a mistake in the other section, it works now. Thank you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by