Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

how to write loop for in for

1 vue (au cours des 30 derniers jours)
vaya putra
vaya putra le 8 Juil 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
i have problem during the looping
i read "output.vtu"
the condition how to store is
  1. every km max is 100 that is why i write the condition x<100 ; x>=100; x>200
  2. each value have subtract with a. that always start from 1-100. i hope since the a=100 , the value x is reach x>=100. then changes to next condition.
but i am struggle how to combine between x interation and a.
A=readfile('output.vtu')';
C = A(10217:13618);
C=cellfun(@(x)sscanf(x,'%f'),C,'UniformOutput',false);
format long g
pf=cell2mat(C); % 0 represents fracture occurs
pf(pf<0.1) =10000; %
km=nan(1000,1); % total cell permeability multiplier
for x=1:10000
for a=1:100
if x<100
km(x,:)=1/8*(pf(x,1)+pf(x+1,1)+pf(200+x,1)+pf(201+x,1)+pf(10201+x,1)+pf(10202+x,1)+pf(x+10401,1)+pf(x+10402,1));
elseif x>=100
km(x,:)=1/8*(pf(201-a,1)+pf(202-a,1)+pf(302-a,1)+pf(303-a,1)+pf(10402-a,1)+pf(10403-a,1)+pf(10503-a,1)+pf(10504-a,1));
elseif x > 199
km(x,:)=1/8*(pf(302-a,1)+pf(303-a,1)+pf(403-a,1)+pf(404-a,1)+pf(10503-a,1)+pf(10504-a,1)+pf(10604-a,1)+pf(10605-a,1));
elseif x >= 200
km(x,:)=1/8*(pf(403-a,1)+pf(404-a,1)+pf(504-a,1)+pf(505-a,1)+pf(10604-a,1)+pf(10605-a,1)+pf(10705-a,1)+pf(10706-a,1));
  1 commentaire
Rik
Rik le 8 Juil 2020
Same as with your previous question (which you chose to delete): there are a lot of end keywords missing. Can you attach the vtu file as well?
And what is your goal? What combinations of a and x do you want to use? Do you want to make sure a is always within the 1-100 range so it loops back to 1 when x goes to 101?
(and for those wondering: the readfile function can be found on the FEX)

Réponses (1)

Rik
Rik le 8 Juil 2020
Modifié(e) : Rik le 8 Juil 2020
Because you want to determine the value of a by looking at x, you need to do just that:
A=readfile('https://www.mathworks.com/matlabcentral/answers/uploaded_files/328823/pf_ext_pcs_1_ts_1_t_1_000000_0.txt');
C = A(10217:13618);
C=cellfun(@(x)sscanf(x,'%f'),C,'UniformOutput',false);
pf=cell2mat(C); % 0 represents fracture occurs
pf(pf<0.1) =10000; %
km=nan(1000,1); % total cell permeability multiplier
for x=1:10000
a=mod(x-1,100)+1;
if x<100
km(x,:)=1/8*(pf(x,1)+pf(x+1,1)+pf(200+x,1)+pf(201+x,1)+pf(10201+x,1)+pf(10202+x,1)+pf(x+10401,1)+pf(x+10402,1));
elseif x>=100
km(x,:)=1/8*(pf(201-a,1)+pf(202-a,1)+pf(302-a,1)+pf(303-a,1)+pf(10402-a,1)+pf(10403-a,1)+pf(10503-a,1)+pf(10504-a,1));
elseif x > 199
km(x,:)=1/8*(pf(302-a,1)+pf(303-a,1)+pf(403-a,1)+pf(404-a,1)+pf(10503-a,1)+pf(10504-a,1)+pf(10604-a,1)+pf(10605-a,1));
elseif x >= 200
km(x,:)=1/8*(pf(403-a,1)+pf(404-a,1)+pf(504-a,1)+pf(505-a,1)+pf(10604-a,1)+pf(10605-a,1)+pf(10705-a,1)+pf(10706-a,1));
end
end
I would also suggest you calculate those offsets. I don't understand exactly the purpose of each part, so it is difficult to recommend code that will solve your problem.
Edit: I changed the extension to txt so it can be attached without zipping. Since it is a plain-text format, that doesn't seem a problem.
  3 commentaires
Rik
Rik le 8 Juil 2020
What do you want to do? Please use more sentences. Use at least a complete sentence for every step. If your English is not good enough, try using short sentences and put them in a machine translator like Google translate.
vaya putra
vaya putra le 8 Juil 2020
in fact the output value that I read is the coordinate node of the unstructured mesh (20400 nodes), each coordinate has a value (0-1) in output.vtu.
my goal is to return the value of the node into 1 value or cell value. (when viewed with paraview, the output consists of 100x100x1, 10000 cells and 20400 nodes)
km is the cell value I'm looking for, pf is the node value of the output file.
km(1,:)=1/8*(pf(1,1)+pf(2,1)+pf(201,1)+pf(202,1)+pf(10201,1)+pf(10202,1)+pf(10401,1)+pf(10402,1))
km(2,:)=1/8*(pf(2,1)+pf(3,1)+pf(200,1)+pf(23-a,1)+pf(10202,1)+pf(10203,1)+pf(10402,1)+pf(10403,1))
km(101,:)=1/8*(pf(200,1)+pf(201,1)+pf(302,1)+pf(301,1)+pf(10201,1)+pf(10202,1)+pf(10401,1)+pf(10402,1))
km(102,:)=1/8*(pf(199,1)+pf(200,1)+pf(301,1)+pf(300,1)+pf(10200,1)+pf(10201,1)+pf(10400,1)+pf(10401,1))
km(10000,:)=1/8*

Cette question est clôturée.

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by