mechanate
Mechanical
- Mar 18, 2010
- 16
Hey guys, I've tried searching for this but haven't been able to find it.
It's been a little since I've done anything relevant in MATLAB and I've run into a little problem with my code. My problem is that I want a program to grab an input for a number of vectors and then I want that program to fill out those vectors based on a number given for a vector size. Let me try and clarify that. I want to calculate a result using 4 column vectors (4 is an arbitrary number given just as an example). I then want to be able to input values for each one of the elements in those vectors. So, I've got a for loop that runs from 1 to the upper bound of the number of vectors and within that loop I've got another for loop that runs from 1 to the upper bound of the vector size. So, in the end I'll end up with A1, A2, A3, A4, all the same size, but with values I enter for each element. A1 could look like [1;7;5;9], A2 like [5;7;5;1] and so on. Has anyone done anything like this before? I'll post my crummy code so you may have a better idea. I know the code doesn't wrong and I know it's at least a problem with my syntax. Thanks in advance!
function [numvectors] = MGS(numvectors)
check = isa(numvectors, 'numeric');
while check == 0;
numvectors = input('Please enter a number\n')
check = isa(numvectors, 'numeric');
end
vectorsize = input('Enter the size of the column vector (A x 1, where A is the size')
for i = 1:numvectors;
str = num2str(i);
for j = 1:vectorsize;
num = input ('Enter number j value for number i matrix')
A(str)(1, j) = num;
end
end
It's been a little since I've done anything relevant in MATLAB and I've run into a little problem with my code. My problem is that I want a program to grab an input for a number of vectors and then I want that program to fill out those vectors based on a number given for a vector size. Let me try and clarify that. I want to calculate a result using 4 column vectors (4 is an arbitrary number given just as an example). I then want to be able to input values for each one of the elements in those vectors. So, I've got a for loop that runs from 1 to the upper bound of the number of vectors and within that loop I've got another for loop that runs from 1 to the upper bound of the vector size. So, in the end I'll end up with A1, A2, A3, A4, all the same size, but with values I enter for each element. A1 could look like [1;7;5;9], A2 like [5;7;5;1] and so on. Has anyone done anything like this before? I'll post my crummy code so you may have a better idea. I know the code doesn't wrong and I know it's at least a problem with my syntax. Thanks in advance!
function [numvectors] = MGS(numvectors)
check = isa(numvectors, 'numeric');
while check == 0;
numvectors = input('Please enter a number\n')
check = isa(numvectors, 'numeric');
end
vectorsize = input('Enter the size of the column vector (A x 1, where A is the size')
for i = 1:numvectors;
str = num2str(i);
for j = 1:vectorsize;
num = input ('Enter number j value for number i matrix')
A(str)(1, j) = num;
end
end