필터 지우기
필터 지우기

How to apply condition for using one variable as input for another in same workspace in matlab?

조회 수: 3 (최근 30일)
I have two variable files which are a polyline file (network.mat) and a point file(sedsource.mat). The elements of the FID_Networ field of the sedsource file are subset of the FID_1 field in the network file. I am trying to use the elements of the sedsource file such that the common elements between the FID_1 of network and the FID_Networ field of sedsoucre file are assigned as 1 and the rest are assigned as 0. I tried to use the following code but wasn't successful. I would be grateful if anyone could help me with this.
Thank You
LinkNum = length(network)
input(1:LinkNum,:)=0;
b = [network.FID_1]';
a = [sedsource.FID_Networ]';
for i = 1:LinkNum
if a(i)==b(i)
input(1:LinkNum,:)=1;
else
input(1:LinkNum,:)=0;
end
end
  댓글 수: 2
Image Analyst
Image Analyst 2020년 12월 25일
input is a built-in function name. Don't use it as the name of your variable.
Niraj Bal Tamang
Niraj Bal Tamang 2020년 12월 25일
Thank You @Image Analyst. Actually, i am using a pre-existing code and just wanted to get the series of values in 1:LinkNum from the sedsource file. The input was already in the code and is repeated in other related matlab files too. Is there a way such that i can assign the elements of the 'a' in the place of 1:LinkNum at the input(1:LinkNum,:)=1; line?That is the main thing i want to do in this code.

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

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 25일
b = [network.FID_1];
a = [sedsource.FID_Networ];
network_is_in_sed = ismember(b, a);
input(1:LinkNum, :) = 0;
input(network_is_in_sed, :) = 1;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by