搜索内容 搜索用户

# [已解决] while循环求助 跳不出来

wlp1818100227 发表于 6 天前
 本帖最后由 wlp1818100227 于 2021-5-4 16:17 编辑 这个是一个矩阵处理过程，History是矩阵名称，传递给Z 循环那里设立一个条件但是无法跳出一直死循环， 绿色是数据处理过程可以忽略， 希望大佬知道一下，想了很长时间了:'( clear;clc; History = zeros(4,4,2); Now = zeros(4,4,2); X = size(History); History(1,1:end,2) = 1; History(2,1:2,2) = 1; History(3,1,2) = 1; %green A History(2,3:end,2) = 3; History(3,end,2) = 3;                     %blue C History(3,2:end-1,2) = 2; History(4,1:end,2) = 2;                 %yellow B id = History(:,:,2) == 1; History(id) = 5;   %假设A地都是5 id = History(:,:,2) == 2; History(id) = 5;   %假设B地都是5 id = History(:,:,2) == 3; History(id) = 3.3; %假设C地都是3.3 %% 求历史网格的平均值 A = find(History(:,:,2) == 1); average_A = mean(History(A)); History(A) = average_A; B = find(History(:,:,2) == 2); average_B = mean(History(B)); History(B) = average_B; C = find(History(:,:,2) == 3); average_C = mean(History(C)); History(C) = average_C; ABS_P = ones(3,1); while abs(ABS_P ) > 0.15 n = X(1,1);m = X(1,2); Z = History; i = 2:n-1; j = 2:m-1; Z(i,j,1) = (History(i+1,j,1) + History(i-1,j,1) + History(i,j+1,1) + History(i,j-1,1))/4; %中间的 Z(1,1,1) = (History(1,2,1) + History(2,1,1))/2; Z(1,n,1) = (History(1,n-1,1) + History(2,n,1))/2; j = 2:n-1; Z(1,j,1) = (History(1,j-1,1) + History(2,j,1) + History(1,j+1,1))/3;           %第一行 Z(m,1,1) = (History(m,2,1) + History(m-1,1,1))/2; Z(m,n,1) = (History(m,n-1,1) + History(m-1,n,1))/2; j = 2:n-1; Z(m,j,1) = (History(m,j-1,1) + History(m-1,j,1) + History(m,j+1,1))/3;          %最后一行 i = 2:m -1; Z(i,1) = (History(i-1,1,1) + History(i,2,1) + History(i+1,1,1)) / 3; %第一列中间两项 Z(i,n) = (History(i-1,n,1) + History(i,n-1,1) + History(i+1,n,1)) / 3; %第n列中间两项 Sum_A1 = sum(Z(A)); Sum_A = sum(History(A)); P_A = Sum_A1\Sum_A; Sum_B1 = sum(Z(B)); Sum_B = sum(History(B)); P_B = Sum_B1\Sum_B; Sum_C1 = sum(Z(C)); Sum_C = sum(History(C)); P_C = Sum_C1\Sum_C; P = [P_A,P_B,P_C]; ABS_P = abs(P-1); if abs(ABS_P ) > 0.15   History(A) = P_A.* Z(A);   History(B) = P_B.* Z(B);   History(C) = P_C.* Z(C); end if abs(ABS_P) < 0.15     break end end if abs(ABS_P ) < 0.15    Now = Z; end

gywxd 发表于 6 天前
 ABS_P  如果一直小于 0.15  那是肯定调不出来的，

2 条回复

## 倒序浏览

gywxd 发表于 6 天前
 ABS_P  如果一直小于 0.15  那是肯定调不出来的，

wlp1818100227 发表于 6 天前
 gywxd 发表于 2021-5-4 18:52 ABS_P  如果一直小于 0.15  那是肯定调不出来的， 啊啊我知道了 感谢帮助
 您需要登录后才可以回帖 登录 | 注册 本版积分规则 回帖后跳转到最后一页