댓글 수: 4

Khalid Mahmood
Khalid Mahmood 2021년 4월 7일
Your question is not clear. What is i?
Khalid Mahmood
Khalid Mahmood 2021년 4월 7일
편집: Khalid Mahmood 2021년 4월 7일
%Supposed this
function y=Question5(x,i)
.....
end
Let, x=randi([-10 10],5,3)
y=Question5(x,3)
Hazal Yuvgun
Hazal Yuvgun 2021년 4월 7일
i is row
Hazal Yuvgun
Hazal Yuvgun 2021년 4월 7일
I want to extract the first row from others

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

 채택된 답변

Khalid Mahmood
Khalid Mahmood 2021년 4월 7일
편집: Khalid Mahmood 2021년 4월 7일

1 개 추천

function y=Question5(x)
y=[];
rows=size(x,1);
y(1,:)=x(1,:);
for i=2:rows
y(i,:)=x(i,:)-x(1,:);
end
end

댓글 수: 3

Hazal Yuvgun
Hazal Yuvgun 2021년 4월 7일
Output is not correct. Output only shows the last row
Khalid Mahmood
Khalid Mahmood 2021년 4월 7일
편집: Khalid Mahmood 2021년 4월 7일
in for loop y(i) ensures all rows. Like y(i,:)=x(i,:)-x(1,:); This is working now
Hazal Yuvgun
Hazal Yuvgun 2021년 4월 7일
Thank you so much

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

추가 답변 (2개)

Steven Lord
Steven Lord 2021년 4월 7일

0 개 추천

Where in your code do you define a variable named i? If the answer is some form of "nowhere" or "I don't" then MATLAB will call the built-in function to determine the value that should be used. That built-in function returns neither a positive integer value nor a logical value.
Khalid Mahmood
Khalid Mahmood 2021년 4월 7일

0 개 추천

function y=Question5(x,i)
y=[];
if i==1
y=x(1,:);
else
y=x(i,:)-x(1,:);
end
end

댓글 수: 1

Khalid Mahmood
Khalid Mahmood 2021년 4월 7일
save above code as Question5.m file. Then
>>x=randi([-10 10],5,3); % define x, or whatever x you want
>>y=Question5(x,1)
>>y=Question5(x,2)
>>y=Question5(x,3)
But I think you may need following code for advanced logic.

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2021년 4월 7일

댓글:

2021년 4월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by