# Issue with the variable after exiting for loop

2 visualizzazioni (ultimi 30 giorni)
Ganesh Kini il 28 Mag 2020
Risposto: Fangjun Jiang il 28 Mag 2020
for ioc = 1: 1: length (ring_vec)
for ipc = 1: 1: length (opcon_vec)
for irc = 1: 1: length (rccorner_vec)
for inw = 1: 1: length (nw_vec)
for ivw = 1: 1: length (pw_vec)
for ivdp = 1: 1: length (vd_vec)
for itp = 1: 1: length (temp_vec)
abc_p = period_arr (ioc, ipc, irc, inw, ivw, ivdp, itp);
end
end
end
end
end
end
end
dist_p = abs (period_arr - abc_p);
[min_dist_p, idx_p] = min (dist_p (:));
%%%%%%%%%%%%%%%%%%%%%%%%%%
results:
dist_p = 1.98
abc_p is just taking one value of size 1 * 1, it should take a matrix of values ​​in 2 * 7 * 1 * 10 * 10 * 15 * 8
How do i get it? Do i need to declare abc_p before the for loop, if so how ?? #
Please help
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Fangjun Jiang il 28 Mag 2020
Yes.
before the loop
abc_p=zeros(length (ring_vec), length (opcon_vec), length (rccorner_vec) ,....), matching the size
inside the loop
abc_p(ioc, ipc, irc, inw, ivw, ivdp, itp) = period_arr (ioc, ipc, irc, inw, ivw, ivdp, itp);
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Loops and Conditional Statements 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!

Translated by