Hi RAFFAELE
To obtain a matrix (i, k) instead of a vector, you can preallocate the matrix S before the loop and assign the values inside the loop. Since you have not provided your complete code, you may refer to the below snippet and make the changes accordingly in your code.
S = zeros(numel(tinj), numel(t)); % Preallocate matrix S with dimensions (numel(tinj), numel(t))
for i = 1:numel(tinj)
t = linspace(0, tinj(i), 20);
for k = 1:numel(t)
S(i, k) = fzero(@(S) myfun(S,t(k)),0.03); % Find the root of myfun(S,t(k)) and store it in S(i, k)
end
end
This will give you a matrix S with dimensions (i, k), where i corresponds to the elements of tinj and k corresponds to the elements of t.