Change the value in multiple text file?

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data 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