Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
[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 comentarios
Ameer Hamza
Ameer Hamza el 3 de Mayo de 2020
What code do you want to make? What are you trying to do with these variables?
DEWDROP
DEWDROP el 4 de Mayo de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 3 de Mayo de 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 comentarios
Image Analyst
Image Analyst el 4 de Mayo de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by