thank you for helping. actually it is easy to implement if I use a(1) in stead of a(0).I just wanted to learn that. So,ıf there is no way to do, I will do using a(1).
Not sure if this is what you meant, but the code below will do EXACTLY what you said. This code willreplace the nth element only, with the sum of the elements from 1 to n, and leave the other elements of A unchanged. n is 100. If that's not what you meant, then please be specific.
% Define sample data of length 120.
A = randi(9, 1, 120)
n = 100; % or whatever element you want to stop at.
fprintf('A(%d) initially equals %d\n', n, A(n));
% Replace the nth element only, with the sum of the elements from 1 to n.
% Leave the other elements of A unchanged!
A(n) = sum(A(1:n))
fprintf('but now A(%d) equals %d\n', n, A(n));
Note: because MATLAB starts at 1 but you started at 0, you may have to adjust n or else adjust the sum:
A(n) = sum(A(1:n+1)); % n=8 is the 9th element if you consider A starting at 0
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Translated by
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.