How to specify size of row and column vector

*If we have a row vector A
and a column vector B
How do we specify the size for both vectors ?*

 채택된 답변

Wayne King
Wayne King 2013년 9월 27일
편집: Wayne King 2013년 9월 27일

0 개 추천

sizeofvector = input('What size vector do you want? Enter the size in brackets, e.g. [100 1]\n');
%%%user enters [1 1000]
x = 10+10*rand(sizeofvector(1),sizeofvector(2));

댓글 수: 2

Mohamad
Mohamad 2013년 9월 28일
Awesome this is what I was looking for. One question. How do you explain this "10+10*rand" . what if i want the numbers to be between 10 and 100 ?
Thanks
If you look up rand, you'll see this in the help:
Example 1
Generate values from the uniform distribution on the interval [a,b]:
r = a + (b-a).*rand(100,1);
I assume you know that a=10 and b=100 and can figure everything else.

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

추가 답변 (2개)

Wayne King
Wayne King 2013년 9월 27일

0 개 추천

How do you find the size, or how do you specify?
To find the size, simply use length()
A = randn(100,1);
length(A)
If you want to pre-allocate, then you can use zeros()
A = zeros(100,1);
If this is not answering your question, can you please elaborate and give an example.

댓글 수: 1

Mohamad
Mohamad 2013년 9월 27일
Not really what I was looking for but still helpful.
My question was let us say u want to prompt a user to specify the size of a row vector and a column vector, that has random numbers between 10 and 20. how do u create that row vector and column vector, that has been specified with a size

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

Image Analyst
Image Analyst 2013년 9월 28일

0 개 추천

Try this:
% Ask user for a number.
defaultValue = {'7'; '5'};
titleBar = 'Enter a value';
userPrompt = {'Enter the row vector width '; 'Enter the column vector height '};
caUserInput = inputdlg(userPrompt, titleBar, 2, defaultValue);
if isempty(caUserInput),return,end; % Bail out if they clicked Cancel.
rowWidth = str2double(caUserInput{1})
columnHeight = str2double(caUserInput{2})
% Make the row vector and column vector with some arbitrary values.
rowVector = zeros(1, rowWidth)
columnVector = ones(columnHeight, 1)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2013년 9월 27일

댓글:

2013년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by