필터 지우기
필터 지우기

I am almost a beginner in MATLAB. Dear all, I want to make code using FOR because node 1 to 4 has same value, and 5 to 8 also has same value.THANK YOU

조회 수: 5 (최근 30일)
[node1]=[0 0 0 1 1 1];
[node2]=[0 0 0 1 1 1];
[node3]=[0 0 0 1 1 1];
[node4]=[0 0 0 1 1 1];
[node5]=[1 1 1 1 1 1];
[node6]=[1 1 1 1 1 1];
[node7]=[1 1 1 1 1 1];
[node8]=[1 1 1 1 1 1];
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2020년 5월 3일
What code do you want to make? What are you trying to do with these variables?
DEWDROP
DEWDROP 2020년 5월 4일
i want to use loop condition to shorten the code because sometimes i need to deal with more than 50 nodes.
Also,while making loop ,i want to display the output as above.

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

채택된 답변

Image Analyst
Image Analyst 2020년 5월 3일
OK, your code looks like it does that, but without a for loop, which is not needed unless you want a 2-D array rather than individual variables. Nodes 1 through 4 have one value (array), which is the same for all 4. And nodes 5-8 also have the same value, but different than nodes 1-4. So what's the problem? Do you have a question? As it is, this is just an announcement.
If you wanted a for loop, you could do
allNodes = ones(8, 6); % Initialize to all ones
for row = 1 : 4
allNodes(row, :) = [0 0 0 1 1 1];
end
At least that's one way to use a for loop. There are others.
  댓글 수: 3
Image Analyst
Image Analyst 2020년 5월 4일
You can append this loop if you want to print them out:
for row = 1 : size(allNodes, 1)
fprintf('node %d = [', row);
fprintf('%d ', allNodes(row, :));
fprintf(']\n');
end
It displays the output (in the command window of course):
node 1 = [0 0 0 1 1 1 ]
node 2 = [0 0 0 1 1 1 ]
node 3 = [0 0 0 1 1 1 ]
node 4 = [0 0 0 1 1 1 ]
node 5 = [1 1 1 1 1 1 ]
node 6 = [1 1 1 1 1 1 ]
node 7 = [1 1 1 1 1 1 ]
node 8 = [1 1 1 1 1 1 ]
exactly like you wanted.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by