フィルターのクリア

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.
DEWDROP
DEWDROP 2020 年 5 月 5 日
it does exactly as i want .THANKS..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by