generate unit vectors based on matrix size

조회 수: 1 (최근 30일)
Nitish Reddy Kotkur
Nitish Reddy Kotkur 2019년 10월 16일
댓글: Nitish Reddy Kotkur 2019년 10월 17일
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.

채택된 답변

James Tursa
James Tursa 2019년 10월 16일
편집: James Tursa 2019년 10월 16일
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.
  댓글 수: 3
Steven Lord
Steven Lord 2019년 10월 16일
The variables v (lower-case) and V (upper-case) are two different variables.
v = 'abracadabra';
V = 1:5;
whos
In the example above whos shows that v and V have different sizes, bytes, and classes.
Nitish Reddy Kotkur
Nitish Reddy Kotkur 2019년 10월 17일
and how do i make a transpose of it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by