필터 지우기
필터 지우기

How to get all value with for loop

조회 수: 2 (최근 30일)
han han
han han 2020년 7월 22일
편집: Alan Stevens 2020년 7월 22일
I want to extract my value(str) under this loop
But he always grabs the last value, not all values
How to modify it?
[Nodelocation] = textread('observe/mdNodeLocationXY_axisforGUI2.txt');
[UElocation] = textread('observe/mdUELocationforGUI2.txt');
[AssignCell] = textread('observe/AssignCell.txt');
scatter(Nodelocation(:,2),Nodelocation(:,3),150,'k','^','filled')
hold on;
inputNodeID =0; % 0 v 1
for ii=1:length(Nodelocation(:,1))
for jj=1:length(UElocation(:,1))
if AssignCell(jj,2) == Nodelocation(ii,1)
if Nodelocation(ii,1) == 0 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
str = string(AssignCell(jj,1));
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
if Nodelocation(ii,1) == 1 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
str = string(AssignCell(jj,1));
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
end
end
end

답변 (1개)

Alan Stevens
Alan Stevens 2020년 7월 22일
편집: Alan Stevens 2020년 7월 22일
Use a counter? Something like the following perhaps:
counter = 0;
for ii=1:length(Nodelocation(:,1))
for jj=1:length(UElocation(:,1))
if AssignCell(jj,2) == Nodelocation(ii,1)
if Nodelocation(ii,1) == 0 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
counter = counter+1;
str(counter) = string(AssignCell(jj,1));
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
if Nodelocation(ii,1) == 1 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
counter = counter+1;
str(counter) = string(AssignCell(jj,1));
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
end
end
end
or possibly:
str = [];
for ii=1:length(Nodelocation(:,1))
for jj=1:length(UElocation(:,1))
if AssignCell(jj,2) == Nodelocation(ii,1)
if Nodelocation(ii,1) == 0 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
str = [str; string(AssignCell(jj,1))];
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
if Nodelocation(ii,1) == 1 && ii == inputNodeID+1
a = scatter(Nodelocation(ii,2),Nodelocation(ii,3),150,[1 0 0],'^','filled');
hold on;
b = scatter(UElocation(jj,2),UElocation(jj,3),50,[0 0.5 0],'x');
str = [str; string(AssignCell(jj,1))];
c = text(UElocation(jj,2),UElocation(jj,3),str);
end
end
end
end

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by