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 visualizzazioni (ultimi 30 giorni)
[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 Commenti
DEWDROP
DEWDROP il 4 Mag 2020
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.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 3 Mag 2020
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 Commenti
Image Analyst
Image Analyst il 4 Mag 2020
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.

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by