求助!!!此类型的变量不支持使用点进行索引。出错 Points_directions (line 19)xdimension = length(mydata{1}.cdata(1,:));

clc
clear all
close all

% Assignments
zdimension = 99;
% Subvolume is the region in which 3D data will be cut around three-phase
% contact point
subvolume = 100;
subvolume = subvolume/2;
mydata = cell(1, zdimension);
% Import .tif images in MATLAB
% !!If different number of figures, change %03d!!
for k = 1:zdimension
  myfilename = sprintf('CPline%03d.tif', k);
  mydata{k} = imread(myfilename);
end

xdimension = length(mydata{1}.cdata(1,:));
ydimension = length(mydata{1}.cdata(:,1));
% Automatic search of interface points
interfaces=zeros(ydimension,xdimension,zdimension);
for k=1:zdimension
interfaces(:,:,k)=mydata{k}.cdata;
end
% Save interface points in variable IP
n=1;
for x=1:length(interfaces(1,:,1))
    for y=1:length(interfaces(:,1,1))
        for z=1:length(interfaces(1,1,:))
            if interfaces(y,x,z)==1
                IP(n,1)=x;
                IP(n,2)=y;
                IP(n,3)=z;
                n=n+1;
            end
        end
    end
end
% Compute the normal directions WITHOUT moving average
for k = 1:length(IP)-1
    dir_IP(:,k) = [IP(k+1,1)-IP(k,1)
        IP(k+1,2)-IP(k,2)
        IP(k+1,3)-IP(k,3)];
    IP_norm_dir(k)=norm(dir_IP(:,k));
    IP_dir_normalized(:,k)=dir_IP(:,k)./IP_norm_dir(k);
end
IP_dir_normalized=IP_dir_normalized';
% Save interface points, along with coordinates of subvolume
points_directions_subvolume = [IP(1:end-1,:), IP_dir_normalized, IP(1:end-1,:)-subvolume];
dlmwrite('points_directions_subvolume.txt',points_directions_subvolume,'delimiter','\t','precision',5)

% Compute moving average of interface line
IP_movavg_4 = tsmovavg(IP,'s',4,1);
% Compute normal directions from moving average
for k = 4:length(IP_movavg_4)-1
    dir_IP_movavg(:,k) = [IP_movavg_4(k+1,1)-IP_movavg_4(k,1)
        IP_movavg_4(k+1,2)-IP_movavg_4(k,2)
        IP_movavg_4(k+1,3)-IP_movavg_4(k,3)];
    IP_norm_dir_movavg(k)=norm(dir_IP_movavg(:,k));
    IP_dir_normalized_movavg(:,k)=dir_IP_movavg(:,k)./IP_norm_dir_movavg(k);
end
IP_dir_normalized_movavg=IP_dir_normalized_movavg';
% Plot interface points (without moving average)
scatter3(IP(:,1),IP(:,2),IP(:,3),'*b')
xlabel('x')
ylabel('y')
zlabel('z')
hold on
% Set the dimension of the region where to extract portions of contact
% line, where to compute the moving average
k_ROI=10;

point_direction_subvolume_ROI=zeros(length(IP(:,1)),9);
for n=1:length(IP(:,1))

    x_E=IP(n,1)-k_ROI;
    x_W=IP(n,1)+k_ROI;
    y_S=IP(n,2)-k_ROI;
    y_N=IP(n,2)+k_ROI;
    z_L=IP(n,3)-k_ROI;
    z_U=IP(n,3)+k_ROI;
    if x_E<=0
        x_E=1;
    end
    if y_S<=0
        y_S=1;
    end
    
    threep_line_ROI=zeros('like',interfaces);
    threep_line_ROI(y_S:y_N,x_E:x_W,z_L:z_U)=interfaces(y_S:y_N,x_E:x_W,z_L:z_U);
    % Find points of three phase contact line in the subregion

    [y_ROI{n},x_ROI{n},z_ROI{n}]=ind2sub(size(threep_line_ROI),find(threep_line_ROI));

    
    ROI{n}=[x_ROI{n},y_ROI{n},z_ROI{n}]';
    % Compute moving average between points in the subregion
    movavg_4{n}=tsmovavg(ROI{n},'s',4,2);
    % Compute triangolar moving average
    movavg_4tr{n}=tsmovavg(ROI{n},'t',4,2);
    
    for k=4:length(movavg_4{n})-1
        dir{n}(:,k-3)=[movavg_4{n}(1,k+1)-movavg_4{n}(1,k);movavg_4{n}(2,k+1)-movavg_4{n}(2,k);movavg_4{n}(3,k+1)-movavg_4{n}(3,k)];
        norm_dir{n}(k-3)=norm(dir{n}(:,k-3));
        dir_normalized{n}(:,k-3)=dir{n}(:,k-3)./norm_dir{n}(k-3);
    end
    
    point_direction_subvolume_ROI(n,:)=[movavg_4{n}(:,4)', dir_normalized{n}(:,1)', movavg_4{n}(:,4)'-subvolume];

end
% Save new coordinates in .txt file
dlmwrite('points_directions_subvolume_movavg.txt',point_direction_subvolume_ROI,'delimiter','\t','precision',5)

scatter3(IP(:,1),IP(:,2),IP(:,3),'*b')
xlabel('x')
ylabel('y')
zlabel('z')
% Save the coordinates of interface points
IPcoordinates = IP;
save('IPcoordinates','IPcoordinates')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值