Hi, I have variable "y"
y = 2
and I have cell array "k"
k = [1] [2] [4] [5] [6] [7] [8] [9]
_______________________________________
what is the best way to get the information that "y" is equal to a certain index in "k".
I can't do it with strcmp, since it returns zeros to all 9 entries of "k".
Thank you.
|
|
0
|
|
|
|
Reply
|
c
|
12/28/2009 7:07:04 PM |
|
If your cell array is just individual numbers, why not convert it to a vector using cell2mat?
|
|
0
|
|
|
|
Reply
|
Andy
|
12/28/2009 7:24:04 PM
|
|
Thank you, but that won't do it for me. Let me ask you this, then:
How do you convert those 9 doubles in the cell array to char's?
Thanks
|
|
0
|
|
|
|
Reply
|
c
|
12/28/2009 7:49:04 PM
|
|
Who said anything about characters? Indexes to arrays are numbers,
your "y" is a number, and your cell array appears to be numbers (since
there are no ' around them), so why are you talking about characters
now?
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
12/28/2009 7:56:00 PM
|
|
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <2e65e1cb-ec77-46a0-a836-c11d196015a7@l2g2000vbg.googlegroups.com>...
> Who said anything about characters? Indexes to arrays are numbers,
> your "y" is a number, and your cell array appears to be numbers (since
> there are no ' around them), so why are you talking about characters
> now?
Because I want to use strcmp...
|
|
0
|
|
|
|
Reply
|
c
|
12/28/2009 8:07:04 PM
|
|
"c cc" <cruzadas@guerrillamailblock.com> wrote in message <hhb358$gf5$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <2e65e1cb-ec77-46a0-a836-c11d196015a7@l2g2000vbg.googlegroups.com>...
> > Who said anything about characters? Indexes to arrays are numbers,
> > your "y" is a number, and your cell array appears to be numbers (since
> > there are no ' around them), so why are you talking about characters
> > now?
>
> Because I want to use strcmp...
In that case, I suppose you'll need a loop to convert each value to a string (num2str), then compare it to y, also converted to a string.
Doesn't seem logical to me to compare everything as strings, but to each his own. :o]
|
|
0
|
|
|
|
Reply
|
Vince
|
12/28/2009 8:13:02 PM
|
|
On Dec 28, 3:07=A0pm, "c cc" <cruza...@guerrillamailblock.com> wrote:
> Because I want to use strcmp...
(Loud sound of hand slapping forehead)
|
|
0
|
|
|
|
Reply
|
ImageAnalyst
|
12/28/2009 8:31:01 PM
|
|
Damn that's a whole lot of work. I think there should be a function.
|
|
0
|
|
|
|
Reply
|
c
|
12/28/2009 8:35:20 PM
|
|
"c cc" <cruzadas@guerrillamailblock.com> wrote in message <hhb4q8$1n4$1@fred.mathworks.com>...
> Damn that's a whole lot of work. I think there should be a function.
That's because you're not comparing numbers, you're comparing strings. Strings are not numbers. Making a function to compare numbers as strings doesn't make sense, because those numbers can easily be compared... as numbers!... and then, if need be, converted to strings (for output).
|
|
0
|
|
|
|
Reply
|
Vince
|
12/28/2009 8:59:04 PM
|
|
> I can't do it with strcmp, since it returns zeros to all 9 entries of "k".
Why?
You guys seem to be a cross-purposes.
Give an insight to why you want to use strcmp.
From your explanation, so far, I'm just not getting it. Tell us the things that makes it sensible to use strcmp.
|
|
0
|
|
|
|
Reply
|
Neil
|
12/28/2009 9:06:04 PM
|
|
"c cc" <cruzadas@guerrillamailblock.com> wrote in message <hhb4q8$1n4$1@fred.mathworks.com>...
> Damn that's a whole lot of work. I think there should be a function.
Okay, let's start from the beginning again. Why can you not use cell2mat?
|
|
0
|
|
|
|
Reply
|
Andy
|
12/28/2009 9:09:04 PM
|
|
Damn guys, you all need to chill.
I needed to use strcmp because that's what my professor asked me to do, for studying the strcmp function purposes. Efficiency was not required.
Nevermind fellas. I didn't solve the problem. The deadline for my solution was reached.
Thank you all anyway. Later!
|
|
0
|
|
|
|
Reply
|
c
|
12/28/2009 10:34:04 PM
|
|
Dear c!
> Damn guys, you all need to chill.
>
> I needed to use strcmp because that's what my professor asked me to do, for studying the strcmp function purposes. Efficiency was not required.
>
> Nevermind fellas. I didn't solve the problem. The deadline for my solution was reached.
I think, you did solve the problem!
You've learned, that the application of a tool, which does not match the problem, is a mess. Do not use STRCMP to compare numbers.
Do not use a can opener to start a car -- although it works with some fiddling.
But using FINDSTR to dig in a row-vector of doubles works fine! So in addition: Not every command containing "STR" is for strings only, but some are.
Kind regards, Jan
|
|
0
|
|
|
|
Reply
|
Jan
|
12/29/2009 1:26:04 AM
|
|
"c cc" <cruzadas@guerrillamailblock.com> wrote in message <hhbbor$ikd$1@fred.mathworks.com>...
> Damn guys, you all need to chill.
>
> I needed to use strcmp because that's what my professor asked me to do, for studying the strcmp function purposes. Efficiency was not required.
>
> Nevermind fellas. I didn't solve the problem. The deadline for my solution was reached.
>
> Thank you all anyway. Later!
Well, just to give this a sense of closure, this is my best guess at what your professor was after:
kchar=cellfun(@(x) char(x), k, 'uniformoutput',0);
any( strcmp(char(y),kchar) ),
|
|
0
|
|
|
|
Reply
|
Matt
|
12/29/2009 1:49:03 AM
|
|
|
13 Replies
291 Views
(page loaded in 0.105 seconds)
Similiar Articles: Compare numbers - comp.soft-sys.matlab"c cc" <cruzadas@guerrillamailblock.com> wrote in message <hhb358$gf5$1@fred.mathworks.com>... > ImageAnalyst <imageanalyst@mailinator.com> wrote in message <2e65e1cb ... compare alphanumeric number with integer problem - comp.lang ...I want to compare the address number in javascript, and the address number is alphanumeric. I have a text box and the user needs to enter the number b... Bitwise comparison of 2 numbers - comp.lang.awkCompare Two Number Arrays - comp.soft-sys.matlab Bitwise comparison of 2 numbers - comp.lang.awk Compare Two Number Arrays - comp.soft-sys.matlab Bitwise comparison of 2 ... Compare Two Number Arrays - comp.soft-sys.matlabHi, I have two arrays: date_array1 = [ 20101201; 20091201; 20091101; 20100101 ]; date_array2 = [ 20081201; 20101201; 20091201; 20061201; 2010... How compare two dates or convert date to number - comp.lang.perl ...Perl neophyte here. I have a record date in the format mm/dd/yyyy and I want to compare it to another date in the same format. Is there a simple w... Compare strings as integers - comp.unix.solarisHello, I have 2 strings in a script (sh) that I want to compare. The two strings are parsed from a version number. num1=1 num2=2 I want to do the f... Find mode - compare two fields - comp.databases.filemaker ...Can't figure this out... Two number fields - can I do a find where field 1 > field 2? ... VisualC++ vs GCC: read in a number in exponential notation - comp ...On 2010-06-06 06:18:10 -1000, Lailoken said: > But the gist of it is that you cannot, *should not*, use '=' to > compare floating point numbers in any application where ... wrong week number in date format - comp.databases.ms-access ...Comparing start and stop dates - comp.soft-sys.sas wrong week number in date format - comp.databases.ms-access ... Comparing two dates -- What am I doing wrong? - comp ... Large numbers, floating point number questions - comp.lang.c ...VisualC++ vs GCC: read in a number in exponential notation - comp ..... Post Question | ... should not*, use '=' to > compare floating point numbers in ... 0003" and "3 ... Reshaping Matrix when "Blocks" Have Unequal Number of Rows - comp ...unique rows of a matrix problem - comp.soft-sys.matlab > Hello, > > Lets say that I have a matrix: > > N=[ 1 ... compare alphanumeric number with integer problem - comp ... plotting two data series of different number of elements - comp ...intersection of two arrays - comp.soft-sys.matlab plotting two data series of different number of elements - comp ... Compare Two Number Arrays - comp.soft-sys.matlab ... Find elements in a cell array and index the cell number - comp ...Compare Two Number Arrays - comp.soft-sys.matlab Find elements in a cell array and index the cell number - comp ... Compare Two Number Arrays - comp.soft-sys.matlab Find ... CUDA: Customize number of used processors - comp.soft-sys.matlab ...Hey there, I want to calculate a jacobi matrix with a finite-difference-method and want to benchmark and compare it to CPU calculation. Now I have ... Counting the number of times a user hits an html form - comp ...Counting the number of times a user hits an html form - comp ... I have a ... compare alphanumeric number with integer problem - comp.lang ... I have a text box and the user ... Comparing Numbers: Greater Than and Less ThanTips and advice on how to help your child evaluate and compare numbers including greater than and less than comparisons. Compare Numbers Game ICompare Numbers Game - Compare numbers upto a 10,000. Click the sign (Less Than, Equal To, or Greater Than) that will make the number sentence true. 7/25/2012 3:49:58 AM
|