Change the value in multiple text file?

1 visualización (últimos 30 días)
audi rachman
audi rachman el 26 de Jul. de 2021
Respondida: KSSV el 26 de Jul. de 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

Respuestas (1)

KSSV
KSSV el 26 de Jul. de 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) ;

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by