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

3 次查看(过去 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];

采纳的回答

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 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by