|
楼主 |
发表于 2010-4-21 11:16
|
显示全部楼层
谢谢楼上各位指点!!!我改改看!
少了一个分号。。添上之后能运行了,但是输出的TXT文件乱码。。怎么会这样呢?
fid=fopen('F:\MAN_TISSUE3-6.dat','r'); human_lin=fread(fid,'uint8'); fclose(fid);
nx=493; ny=87; nz=147; human3d=zeros(nx,ny,nz); i=1;
for z=1:nz, for y=1:ny, for x=1:nx
human3d(x,y,z)=human_lin(i); i=i+1;
end; end; end
save F:\human3d.mat; load F:\human3d.mat
SZ1=[0 1 2 9 10 11 12 13 14 17 18 20 31 77 94 95 96 97 110 4 6 7 8 30];
for c=1:nz, for b=1:ny, for a=1:nx
if(~length(find(SZ1==human3d(a,b,c))))
human3d(a,b,c)=120;
end
end; end; end
for c=1:nz, for b=1:ny, for a=1:nx
if human3d(a,b,c)==2, human3d(a,b,c)=15; end
end; end; end
for c=1:nz, for b=1:ny, for a=1:nx
if (human3d(a,b,c)==1), human3d(a,b,c)=2; end
if (human3d(a,b,c)==4||human3d(a,b,c)==6||human3d(a,b,c)==7||human3d(a,b,c)==8||human3d(a,b,c)==30)
human3d(a,b,c)=3; end
if (human3d(a,b,c)==9), human3d(a,b,c)=4; end
if (human3d(a,b,c)==10), human3d(a,b,c)=5; end
if (human3d(a,b,c)==11), human3d(a,b,c)=6; end
if (human3d(a,b,c)==12), human3d(a,b,c)=7; end
if (human3d(a,b,c)==13), human3d(a,b,c)=8; end
end; end; end
for c=1:nz, for b=1:ny, for a=1:nx
if (human3d(a,b,c)==14), human3d(a,b,c)=9; end
if (human3d(a,b,c)==17), human3d(a,b,c)=10; end
if (human3d(a,b,c)==18), human3d(a,b,c)=11; end
if (human3d(a,b,c)==20), human3d(a,b,c)=12; end
if (human3d(a,b,c)==31), human3d(a,b,c)=13; end
end; end; end
for c=1:nz, for b=1:ny, for a=1:nx
if (human3d(a,b,c)==77), human3d(a,b,c)=14; end
if (human3d(a,b,c)==94), human3d(a,b,c)=16; end
if (human3d(a,b,c)==95), human3d(a,b,c)=16; end
if (human3d(a,b,c)==96), human3d(a,b,c)=16; end
if (human3d(a,b,c)==97), human3d(a,b,c)=16; end
if (human3d(a,b,c)==110), human3d(a,b,c)=17; end
end; end; end
save F:\human3d.mat ; load F:\human3d.mat
FID=fopen('human3d.txt','w');
for c=1:nz, for b=1:ny, for a=1:nx
k=human3d(a,b,c); l=[a,b,c,k,k,k]; fprintf(FID,'%f %f %f %f %f %f\n',l);
end; end; end
fclose(FID); save F:\human3d.txt
上面是完整程序。
任务是:读取一个DAT文件,然后修改数组的值,最后输出txt
求指教!不知道哪错了,输出的TXT是乱码
在输出前,输入human3d(20,20,20)等还能显示正整数,用DISP显示也能符合要求,为什么输出TXT就乱码了呢?
[ 本帖最后由 ChaChing 于 2010-4-21 14:13 编辑 ] |
|