Why does the window show me Number of columns on line 9 of ASCII file GOA_algorithm_2.m must be the same as previous lines,and my both subroutine are m.files

조회 수: 1 (최근 30일)
I want to run this main file with two subroutines ,but the window always show me
Error using load
Number of columns on line 9 of ASCII file
GOA_algorithm_2.m must be the same as previous
lines.
Error in final_op4_Pq_P_Tq (line 2)
load('GOA_algorithm_2.m','P_q')
Error in GOA_algorithm_2 (line 22)
[P_Tq]=final_op4_Pq_P_Tq(P_q)
main file
clear
%declare
K=4;
N=4;
L=5;
xi=10^-4
nois_var_hk_2pow=0.1*(L^(-2.5))*10;
nois_var_ak_2pow=[1.0000e-10 1.0000e-10 1.0000e-10 1.0000e-10 ];
nois_var_dk_2pow=[1.0000e-08 1.0000e-08 1.0000e-08 1.0000e-08 ];
bar_r=[10 10 10 10];
P_T=10
%===========================================================
P_ub=0.0824;
P_lb=1.6236*10^-9;
%==================================================
% declare the initial P_p and P_q
P_p=P_ub-0.618*(P_ub-P_lb);
P_q=P_lb+0.618*(P_ub-P_lb);
%==============================
%using op4_Pp_P_TP and op4_Pq_P_Tq
[P_Tq]=final_op4_Pq_P_Tq(P_q)
[P_Tp]=final_op4_Pp_P_Tp(P_p)
%=====================================
delta1=abs(P_T-P_Tp);
delta2=abs(P_T-P_Tq);
delta=min(delta1,delta2);
c=0
%========================
%開始比較
while delta > xi
if delta1 <= delta2
P_ub=P_q;
P_q=P_p;
P_Tq=P_Tp;
P_p=P_ub-0.618*(P_ub-P_lb);
%save('GOA_algorithm_2.m','P_p')
[P_Tp]=final_op4_Pp_P_Tp(P_p)
load('final_op4_Pp_P_Tp','P_Tp')
else
P_lb=P_p;
P_p=P_q;
P_Tp=P_Tq;
P_q=P_lb+0.618*(P_ub-P_lb);
%save('GOA_algorithm_2.m','P_q')
[P_Tq]=final_op4_Pq_P_Tq(P_q)
load('final_op4_Pq_P_Tq','P_Tq')
c=c+1;
end
delta1=abs(P_T-P_Tp);
delta2=abs(P_T-P_Tq);
delta=min(delta1,delta2);
end
%==============================
if delta1 <= delta2
best_P=P_p
[P_Tp]=final_op4_Pp_P_Tp(P_p)
load('final_op4_Pp_P_Tp','P_Tp') % find F_k and rho(k)
else
best_P=P_q
[P_Tq]=final_op4_Pq_P_Tq(P_q)
load('final_op4_Pq_P_Tq','P_Tq')% find F_k and rho(k)
end
one of sub-file
function [P_Tq]=final_op4_Pq_P_Tq(P_q)
load('GOA_algorithm_2.m','P_q')
hat_p_up=P_q
bd=100
bdc=101
AXX3=zeros(1,bd);
lkk=1:bdc
lkkspace=zeros(1,bdc)
rho_k=0:0.01:1
for lkk=1:bdc
%rho_k=0.6
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for dd=1:bd
%OP4
%declare
K=4;
N=4;
L=5;
xi=10^-4
nois_var_hk_2pow=0.1*(L^(-2.5))*10;
nois_var_ak_2pow=[1.0000e-10 1.0000e-10 1.0000e-10 1.0000e-10 ];
nois_var_dk_2pow=[1.0000e-08 1.0000e-08 1.0000e-08 1.0000e-08 ];
bar_r=[10 10 10 10];
P_T=10
%channel build
h_1=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_2=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_3=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_4=normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])+1i*normrnd( 0,sqrt(0.1*(L^(-2.5))) ,[4,1])
h_kk=cat(2,h_1 ,h_2 ,h_3, h_4)
for n=1:4
h_k{n}=h_kk(1:4 , n);
n=n+1;
end
%==========================
cvx_begin
variable FNNK_up(N,N,K) semidefinite;%c7
%==========================
Fkk_up=cat(2,FNNK_up);
up=0
for o_up=1:4
Fk_up{o_up}=Fkk_up(1:4,o_up+3*up:4*o_up)
up=up+1;
end
tr_ace_up=0
for t=1:K
tr_ace_up=tr_ace_up+trace(Fk_up{t})
end
%====================================
%object function
minimize( tr_ace_up )
%====================================
%Constraint
subject to
%===================================================
%c5
c5_left_hand_up = 0;
for k = 1:K
sum_5_up = 0;
for j = 1:K
if j ~= k
sum_5_up = sum_5_up + h_k{k}' * Fk_up{j} * h_k{k};
end
end
c5_left_hand_up = c5_left_hand_up - sum_5_up+ (h_k{k}' * Fk_up{k} * h_k{k}*inv_pos(bar_r(1)))
c5_right_hand_up= nois_var_ak_2pow(1)*rho_k(lkk)+ nois_var_dk_2pow(1)
real( c5_left_hand_up ) *rho_k(lkk) >= c5_right_hand_up
end
%===================================================
%c10
c10_left_hand_up = 0;
sum_10_up = 0;
for j = 1:K
sum_10_up= sum_10_up + h_k{k}' * Fk_up{j} * h_k{k};
end
c10_left_hand_up =real(c10_left_hand_up + sum_10_up+nois_var_ak_2pow(1))*(1-rho_k(lkk))
c10_right_hand_up=hat_p_up
c10_left_hand_up>= c10_right_hand_up
cvx_end
c3(dd)=AXX3(dd)+cvx_optval;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
allthings=c3
ck=1:bd
c(ck)=~isinf(c3(ck))
if c(ck)==0
b(ck)=c(ck)
else
b(ck)=c3(ck)
end
usp=b
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%find which value ,ignore 0, is the minimum value
okoko=usp
iwant=min(okoko)
us(lkk)=lkkspace(lkk)+iwant
allthings_compare=us
min_samepower_diff_rho_F=min(us(us>0))
P_Tq=min_samepower_diff_rho_F
end
save('final_op4_Pq_P_Tq.m','P_Tq')
I don't know why does the window mention the ASCII file,i didn't use the ASCII file before,so i can't understand why the window told me
Number of columns on line 9 of ASCII file
GOA_algorithm_2.m must be the same as previous
lines.
and P_Tq and P_Tp are both a scalar(value)

채택된 답변

yang-En Hsiao
yang-En Hsiao 2019년 4월 3일
In the second code,we can see this line in the begining
load('GOA_algorithm_2.m','P_q')
So,this means we have to load the "P_q" value which is from this code GOA_algorithm_2.m,so we have to save the "P_q" in the GOA_algorithm_2.m first,then we can load it,so we have to add this line in the GOA_algorithm_2.m
P_p=P_ub-0.618*(P_ub-P_lb);
P_q=P_lb+0.618*(P_ub-P_lb);
then add two lines here
save('GOA_algorithm_2.m','P_p')
save('GOA_algorithm_2.m','P_q')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by