フィルターのクリア

How to save variables in txt files while running in a loop

9 ビュー (過去 30 日間)
Vivek Kumar
Vivek Kumar 2022 年 1 月 8 日
編集済み: KSSV 2022 年 1 月 8 日
Here in the below code I want to save V in different txt files. Like V1,V2,V3,V4.....V10. or can I save all the data in one single .txt file ?
clc
clear all
close all
n=10;
for i=1:1:n
for j=1:1:50
V(i,j)=j^2+2*(i+1);
end
end

回答 (1 件)

KSSV
KSSV 2022 年 1 月 8 日
編集済み: KSSV 2022 年 1 月 8 日
clc
clear all
close all
n=10;
for i=1:1:n
for j=1:1:50
V(i,j)=j^2+2*(i+1);
end
end
dlmwrite('filename.txt',V)
Also to create the above matrix, loop is not required.
i = 1:n ;
j = 1:50 ;
[i,j] = meshgrid(i,j) ;
v = j.^2+2*(i+1) ;
v = v' ;

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by