Info
此问题已关闭。 请重新打开它进行编辑或回答。
how to write loop for in for
2 次查看(过去 30 天)
显示 更早的评论
i have problem during the looping
i read "output.vtu"
the condition how to store is
- every km max is 100 that is why i write the condition x<100 ; x>=100; x>200
- 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 个评论
Rik
2020-7-8
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?
回答(1 个)
Rik
2020-7-8
编辑:Rik
2020-7-8
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 个评论
Rik
2020-7-8
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.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!