i have file this:
porecount= 9 throatcount= 10 0 1.16667 -0.666667 0 1 1.16667 -0.333333 0 2 1.16667 0 0 3 1.5 -0.666667 0 4 1.5 -0.333333 0 5 1.5 0 0 6 1.83333 -0.666667 0 7 1.83333 -0.333333 0 8 1.83333 0 0 0 0 1 0.0610206 0.333333 0 1 0 3 0.0606029 0.333333 0 2 1 2 0.0601841 0.333333 0 3 1 4 0.0612494 0.333333 0 4 3 4 0.0593242 0.333333 0 5 3 6 0.0589063 0.333333 0 6 4 5 0.0599607 0.333333 0 7 4 7 0.0595583 0.333333 0 8 6 7 0.0591209 0.333333 0 9 7 8 0.0601974 0.333333 0 you can see: there 2 kinds of object in here, p , t. there 9 p s , 10 ts. there 4 kinds of information p, 1 integer , 3 floating point numbers. there 6 kinds of information t, 3 integers , 3 floating point numbers.
now need matlab program knows how many p , t there, , read every kind of information p 1-d array, , every kind of information t 1-d array.
so there 4 column arrays store p information. , 6 column arrays store t information.
based on knowledge, write following program. , doesn't work, no need say. please me out.
prompt = 'please enter file name: '; filename = input(prompt, 's'); saturationfile=fopen(filename); porecount =fscanf(saturationfile, 'porecount = %d\n', 1); throatcount=fscanf(saturationfile, 'throatcount= %d\n', 1); % p =fscanf(saturationfile, '%d%f%f%f\n', porecount); % p=zeros(4, 1); pi=zeros(porecount, 1); px=zeros(porecount, 1); py=zeros(porecount, 1); ps=zeros(porecount, 1); % t =fscanf(saturationfile, '%f', [throatcount, 6]); ti=zeros(throatcount, 1); tb=zeros(throatcount, 1); te=zeros(throatcount, 1); ta=zeros(throatcount, 1); tl=zeros(throatcount, 1); ts=zeros(throatcount, 1); i=1:porecount % p=fscanf(saturationfile, '%d'); % pi(i)=p(i, 1); % px(i)=p(i, 2); % py(i)=p(i, 3); % ps(i)=p(i, 4); pi(i)=fscanf(saturationfile, '%d' , 1); px(i)=fscanf(saturationfile, '%f' , 1); py(i)=fscanf(saturationfile, '%f' , 1); ps(i)=fscanf(saturationfile, '%d\n', 1); end i=1:throatcount ti(i)=fscanf(saturationfile, '%d' , 1); tb(i)=fscanf(saturationfile, '%d' , 1); te(i)=fscanf(saturationfile, '%d' , 1); ta(i)=fscanf(saturationfile, '%f' , 1); tl(i)=fscanf(saturationfile, '%f' , 1); ts(i)=fscanf(saturationfile, '%d\n', 1); end error message:
in assignment a(i) = b, number of elements in b , must same. error in networksaturationplot (line 29) pi(i)=fscanf(saturationfile, '%d' , 1);
i able 2 structures ttmp , ptmp, 1d cell arrays, each cell array contains data single column. these cell arrays turned regular vectors
clear all;close all;clc saturationfile=fopen('./data.txt'); porecount =fscanf(saturationfile, 'porecount = %d\n', 1); throatcount=fscanf(saturationfile, 'throatcount= %d\n', 1); ptmp=textscan(saturationfile,'%u %f %f %u',porecount); ttmp=textscan(saturationfile,'%u %u %u %f %f %d',throatcount); pi=ptmp{1}; px=ptmp{2}; py=ptmp{3}; ps=ptmp{4}; ti=ttmp{1}; tb=ttmp{2}; te=ttmp{3}; tl=ttmp{4}; ta=ttmp{5}; ts=ttmp{6}; fclose(saturationfile);
Comments
Post a Comment