MATLAB: Generate unit vectors based on matrix size

matrixunitvectorsvectors

function [] = lanczos(A, m)
A = readmatrix('output1.txt','Whitespace',' []');
[n,k] = size(A);
V = zeros(k,k);
%V(:,2) = rand(k,1);
V(:,2)=[1 0 0 0 0 0 0 0 0 0 0]';
the v(:,2) is assigned based on matrix size ,which i did manually.But i need it to be created automaticaly based on matrix size.
for suppose if matrix is of size 5*5 then V(:,2)=[1 0 0 0 0]
if matrix is of size 7*7 then V(:,2)=[1 0 0 0 0 0 0]
if matrix is of size 100*100 then V(:,2)=[1 0 0 0 0……..] i can't hand write such long vector so i need it to be generated automaticaly based on matrix size.

Best Answer

Why not just V(1,2) = 1;
Or if you really need to explicitly set those 0’s then start with V(:,2) = 0; followed by the above.