How to declare a variable that changes it's size after each loop iteration?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to declare/pre-allocate two variables "delay_points_local","CFO_points_local" that change the sizes. How can I declare it? Here is the code:
pdf_tau = step_CFO*sum(g_prime_bar_all_relays(:,:,k),1);
[~,tau_k_pos] = max(pdf_tau);
arg_max_tau(k) = delay_points(1,tau_k_pos);
pdf_CFO = step_tau*sum(g_prime_bar_all_relays(:,:,k),2);
[~,CFO_k_pos] = max(pdf_CFO);
arg_max_CFO(k) = CFO_points(1, CFO_k_pos);
step_CFO = 0.0001;
step_tau = 0.01;
rho_g = 20;
for k = 1 : K
delay_points_local(k,:) = arg_max_tau(k) - 0.3 : step_tau : arg_max_tau(k) + 0.3;
CFO_points_local(k,:) = arg_max_CFO(k) - 0.005 : step_CFO : arg_max_CFO(k) + 0.005;
[g_prime_bar_all_relays_local(:,:,k)] = Importance_function_grid( y_rd , CFO_points_local(k,:) , delay_points_local(k,:) , L , os_factor , K , TrainingSequence(k,:) , rho_g , step_tau , step_CFO,roll_off);
end
0 Commenti
Risposte (2)
CS Researcher
il 7 Mag 2016
I am not completely sure I understand your question but you can do it two different ways:
If the number of columns are fixed:
delay_points_local = zeros(K,N);
for k = 1:K
delay_points_local(k,:) = ... (the way you are doing it)
end
If you are not sure of the column size
delay_points_local = cell(1,K);
for k = 1:K
delay_points_local{1,k} = ...
end
Hope this helps!
3 Commenti
CS Researcher
il 7 Mag 2016
How much does the number of columns change with each iteration? Is the change fixed or variable? If you know the max possible column size you can declare the matrix using that size.
Weird Rando
il 7 Mag 2016
Dunno if this code would run. Basically I modify the for loops and added two variable (temp_delay_points_local, temp_CFO_points_local). The delay_points_local and CFO_points_local will contain 0 padding due to the uneven sizes of the array. It may be better to store them in a cell.
pdf_tau = step_CFO*sum(g_prime_bar_all_relays(:,:,k),1);
[~,tau_k_pos] = max(pdf_tau);
arg_max_tau(k) = delay_points(1,tau_k_pos);
pdf_CFO = step_tau*sum(g_prime_bar_all_relays(:,:,k),2);
[~,CFO_k_pos] = max(pdf_CFO);
arg_max_CFO(k) = CFO_points(1, CFO_k_pos);
step_CFO = 0.0001;
step_tau = 0.01;
rho_g = 20;
for k = 1 : K
temp_delay_points_local = arg_max_tau(k) - 0.3 : step_tau : arg_max_tau(k) + 0.3;
delay_points_local(k,1:numel(temp_delay_points_local)) = temp_delay_points_local;
temp_CFO_points_local = arg_max_CFO(k) - 0.005 : step_CFO : arg_max_CFO(k) + 0.005;
CFO_points_local(k,1:numel(temp_CFO_points_local)) = temp_CFO_points_local;
[g_prime_bar_all_relays_local(:,:,k)] = Importance_function_grid( y_rd , CFO_points_local(k,:) , delay_points_local(k,:) , L , os_factor , K , TrainingSequence(k,:) , rho_g , step_tau , step_CFO,roll_off);
end
2 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!