Change the value in multiple text file?

2 ビュー (過去 30 日間)
audi rachman
audi rachman 2021 年 7 月 26 日
回答済み: KSSV 2021 年 7 月 26 日
Hi, I want change several value on my text file and i'm doing it manually. Is there a faster way to change a value in a multiple text file? All my text file have same matrix dimension.
Here are my example code that i do manually:
ZEE=xlsread('zee.xlsx','Area','B2:MP138');
ZEE=ZEE';
A=load('daya50MW.txt');
B=load('dayaelninoMW.txt');
for i=1:353
for j=1:137
if (ZEE(i,j) == 1)
daya50zee(i,j)=A(i,j);
else
daya50zee(i,j)=NaN;
end
end
end
for i=1:353
for j=1:137
if (ZEE(i,j) == 1)
dayaelninozee(i,j)=B(i,j);
else
dayaelninozee(i,j)=NaN;
end
end
end
Thank you

回答 (1 件)

KSSV
KSSV 2021 年 7 月 26 日
You need not to take a loop, you can straight away use the logical indexing.
ZEE=xlsread('zee.xlsx','Area','B2:MP138');
ZEE=ZEE';
A=load('daya50MW.txt');
B=load('dayaelninoMW.txt');
daya50zee = NaN(size(A)) ;
dayaelninozee = NaN(size(A)) ;
daya50zee(ZEE == 1) = A(ZEE == 1) ;
dayaelninozee(ZEE == 1) = B(ZEE == 1) ;

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by