How can I make this simple code a for loop?

1 回表示 (過去 30 日間)
Ashfaq Ahmed
Ashfaq Ahmed 2021 年 12 月 6 日
回答済み: David Hill 2021 年 12 月 6 日
Hi, how can I represent this simple codes in a for loop? Also, can you please suggest me when I see a similar pattern in my codes, where should I mostly focus on to convert it into a for loop code? I am really bad at making for loops. Is there any good tutorials on it to learn it efficiently?
clear all; close all; clc;
x = 1:1:5;
y = 0;
y1 = x.^1;
plot(x,y1);
hold on
y2 = x.^2;
plot(x,y2);
hold on
y3 = x.^3;
plot(x,y3);
hold on

採用された回答

David Hill
David Hill 2021 年 12 月 6 日
x=1:5;
hold on;
for k=1:3
plot(x,x.^k);
end

その他の回答 (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