How to execute multiple commands at once
조회 수: 30 (최근 30일)
이전 댓글 표시
I think this should be fairly basic but I want to make a function where I put an input array, the function does multiple simples commands and creates an output array
For example
Somthing like
function('input','output') %changes input to output using the following commands at once to the array
output(:,1)=input(:,1)*0.72+74;
output(:,3)=input(:,3)*0.39+170;
output(:,4)=input(:,3)*0.78+57;
output(:,5)=input(:,3)*1.2+0.46;
output(:,9)=input(:,3)*1.1+26;
output(:,13)=input(:,3)*0.52+130;
output(:,14)=input(:,3)*0.63+97;
output(:,15)=input(:,3)*0.66+91;
output(output(:,9)==26,9) = 0; %changes everything that is y intercept to 0
output(output(:,5)==0.460,5) = 0; %changes everything that is y intercept to 0
Thanks!
MATLAB Version: 9.3.0.713579 (R2017b)
댓글 수: 0
답변 (1개)
Fangjun Jiang
2019년 2월 21일
편집: Fangjun Jiang
2019년 2월 21일
You just need to change the first line to below and save it as MyCal.m.
function output=MyCal(input)
You function name would be called MyCal. You use it like
MyCal(magic(15))
type "doc function" to learn how to define function
댓글 수: 6
Walter Roberson
2019년 2월 22일
I suspect it can be coded as a matrix multiplication with a 18 x 19 matrix, starting from eye(18,19) and setting specific coefficients. However the setting of the coefficients would be a nuisance. I guess you could use sparse() to put them in in a compact form, but it would not be clear.
참고 항목
카테고리
Help Center 및 File Exchange에서 Software Development Tools에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!