MATLAB: How can i get in place of %d is i values for each iteration of e

num_nod = 11 num_nod = 11 error using input the second argument to input must be 's'.older duplicate

num_nod=input('num_nod = ')
for e=1:2*num_nod
force(e,1)=input('applied forces at node %d:',e);
end

Best Answer

Ganesh - use sprintf to create your string for the input command
force(e,1) = input(sprintf('applied forces at node %d:',e));
Also, pre-allocate memory to the force array so that it doesn't need to increase size on each iteration of the loop. i.e.
num_nod=input('num_nod = ')
force = zeros(2*num_nod,1);
for e=1:2*num_nod
force(e,1) = input(sprintf('applied forces at node %d:',e));
end
Related Question