Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hugolohrer

macrumors newbie
Original poster
Nov 14, 2011
5
0
Hi,

I was programming here and I stopped at a thing. I'll try to explain.
I have a vector A = [10, 20, 30, 40], than I want to the computer tell me the directly lower number of the vector for reported 'x'.
like so:
x = 23
ans = 20.
but i also want him to tell me the row and column of this number.
type so
x = 23
so , i = 2 ; j = 1
i =column
j=row

i know how to do this in MATLAB language but,
how can i do this in Objective-C language ??????

Thanks
 
Neither C nor obj-C have official multidimensional arrays.

You might try something like:
Code:
int A[2][4] = { 10, 20, 30, 40, 50, 60, 70, 80 }

The above array, though it was called a 2x4, is as far as C is concerned a 1 dimensional array with 8 spaces.

When the user puts in a number it could use a for loop to check each number in the array... and it needs to store which space the number was found in. Then, to convert it back to a two dimensional array, it would look something like...

Code:
row = location/rowLength
column = location%rowLength

Do you get the gist of what I'm saying? Googling "C multidimensional array" might help.
 
Sorry have explain completely wrong.

i will try to explain right this time ...........sorry


I have a vector A = [10, 20, 30, 40], than I want the computer to tell me the directly lower number of the informed number 'x'.
like so:
x = 23
ans = 20.
but i also want him to tell me the position of this number.
like so
x = 23
so , i = 2
"i" is the position of the number in the vector

i know how to do this in MATLAB language but

how can i do this in Objective-C language ??????

Thanks
 
Sorry but I have to ask what you mean by vector when you're talking of Objective-C?

Example code would help, me at least, know for sure how best to guide you to an answer.
 
Sorry but I have to ask what you mean by vector when you're talking of Objective-C?

Example code would help, me at least, know for sure how best to guide you to an answer.

I think he's talking about vector space and doing vector addition and multiplication.
 
sorry....again hehehe

this "vector" is like an array.

i will post here an example of my code for matlab. this code did solve my problem.

So a have the following array:

A=[10;20;30;40;50]

t=input('write the number =')

[K,L]=find(A>t,1,'first')

----------------------

So if the user write ->23

MATLAB tells me this

K=3

L=1

But i just need the "K" value.

hope this help

thanks
 
In other words you have MATLAB code, no Objective-C code and want us to provide you with the equivalent code suitable for use with Objective-C.

Does that sum it up about right?
 
We're not just going to tell you the answer. We're here to help you find the answer for yourself, not do it all for you.

We need to know what you know about obj-c. What have you tried so far?
 
We're not just going to tell you the answer. We're here to help you find the answer for yourself, not do it all for you.

We need to know what you know about obj-c. What have you tried so far?

Oh I don't know about that. I'm known for doing exactly that depending upon the apparent frustrations of the poster!
 
The attitude of the OP of that thread is a great example of why it's not a good idea.

I feel we're both saying the same things from opposite ends. The difference for me that there are some people that need a few working whole examples to study in order to learn.

Probe and determine!
 
I feel we're both saying the same things from opposite ends. The difference for me that there are some people that need a few working whole examples to study in order to learn.

Probe and determine!

Sorry ArtOfWarfare, but you are wrong,

my array is 45x1 (if you understand what's that mean) and my code goes far far far far beyond....
so this is just a little bit of my entire code.

----------

In other words you have MATLAB code, no Objective-C code and want us to provide you with the equivalent code suitable for use with Objective-C.

Does that sum it up about right?



exactly

I asked for help, many many people but they just couldn't answer me correctly.

thank you
 
for those who (whoo are you who who, who who------reference to the music :Who are You ;by The Who) read these post and want the correct answere:

Code:
int main()
{
    int vetor1[] = {10, 20, 30, 40};
    int cont = 0, marc = 0, i = 0;
    int value1;
    marc = 20.5 - 10;
    while(i < 4){
        if(marc > abs(vetor1[i] - 20.5)){
            marc = abs(vetor1[i] - 20.5);
            value1 = vetor1[i];
            cont = i;
        }
        i++;
    }
    printf("numberdirectlower =  %i\n", value1);
    printf("position= %i\n", (cont+1));
    return 0;
}


i did modify a little bit from the one that i'm going to use.
so i don't know if this one is going to run...

sorry.

bye
 
Last edited by a moderator:
Without a better understanding of exactlly what you're wish to accomplish it really is hard to know where to start helping.

As Objective-C is basically a super set of C you may want to stick with C syntax.
 
Before you become too comfortable doing vector-work with for-loops, read through the vForce framework. If you are doing math on every item in a vector, the vForce functions will probably be a lot faster than anything that you or I can write with for-loops (and would probably even smoke matlab).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.