Clear Filters
Clear Filters

Change the value in multiple text file?

2 views (last 30 days)
audi rachman
audi rachman on 26 Jul 2021
Answered: KSSV on 26 Jul 2021
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

Answers (1)

KSSV
KSSV on 26 Jul 2021
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) ;

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!