help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newbie] prefered way to enter the values of a matrix interactively


From: Juan Pablo Carbajal
Subject: Re: [newbie] prefered way to enter the values of a matrix interactively
Date: Tue, 16 Oct 2012 21:36:10 +0200

On Tue, Oct 16, 2012 at 9:18 PM, Jean Dubois <address@hidden> wrote:
>
>
> 2012/10/16 Juan Pablo Carbajal <address@hidden>
>>
>> On Tue, Oct 16, 2012 at 9:04 PM, Jean Dubois <address@hidden>
>> wrote:
>> > What is the prefered way to enter the values of a matrix
>> > interactively. I can imagine this is a common task which can be
>> > performed by a predefined matlab-function and it probably is not a
>> > good idea to try to program a function myself for this?
>> > What I want is something like
>> > enter matrix variable name
>> > e.g. a
>> > enter matrix dimension
>> > e.g. 3
>> > enter element 1,1
>> > enter element 1,2
>> > .
>> > .
>> > .enter element 3,3
>> > a=...
>> >
>> > thanks in advance
>> > _______________________________________________
>> > Help-octave mailing list
>> > address@hidden
>> > https://mailman.cae.wisc.edu/listinfo/help-octave
>> >
>>
>> Hi,
>> I do not see the point of doing this in an interactive language, but
>> anyways check function "input" and "eval"
>>
>>
> Well to give you an example, I want a program which starts by asking the
> user to enter two matrices a and b which will be later used for
> demonstrating some kinds of matrix-operations in octave e.g. the difference
> between a*b and a.*b just to name one example
>
> So, what you are telling me is to program it myself, I think I can do that
> but I can't imagine I'm the first one who needs matrices to be entered
> interactively therefore I was wondering whether there aren't any standard
> functions available in Octave for this task.
>
> best regards,
> jean
>
>

Hi Jean,

Please keep the mailing list always in copy.

Octave is an interactive language, so you can enter a matrix directly
from the command line
A = [1 2; 3 4]

Your program can ask the user to do that before running it. Lets say
you have a script called lademo.m
The user is running octave and executes your demo:

octave:1> lademo

If there isn't a matrix "A" defined then you can print a message asking for it

if !exist ("A","var")
 error("Please define the matrix 'A' before running this demo.\n")
end

This checks for the existence of a variable called "A" it will not
check it size or contents. You can do that by adding checks, for
example if it should be a numerical real array
if !isreal (A)
 # print a message
end

This is much easier than asking the user to introduce element by
element and also simplifies your program by fixing the name of the
matrix.

Hope this helps

Cheers


reply via email to

[Prev in Thread] Current Thread [Next in Thread]