Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
cLin
Apr 21, 2003
lat3nt.net
MySQL QUESTION

code:
column a	| 	column b 	|	column c	|	column d 
word		|	yellow		|	1		|	56
word		|	white		|	323		|	212
word		|	black		|	123		|	4453
word		|	green		|	2		|	125
Is it possible to get the data from the above table to show like this

code:
column a	| 	column b 				|	sum(column c)	|	sum(column d) 
word		|	yellow, white, black, green		|	449		|	4846
Right now I am using

code:
SELECT column a, column b, sum(column c), sum(column d) FROM table_name GROUP BY column a
but obviously the data from column b will only show one value (yellow in my case). I wanted to see how I could basically get every value in column b into one single row.

Adbot
ADBOT LOVES YOU

spiritual bypass
Feb 19, 2008

Grimey Drawer
This'll probably do it

http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

cLin
Apr 21, 2003
lat3nt.net
Nice, thanks. I was using CONCAT() but it didn't seem to do what I wanted to do.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
This is going to be stupidly easy for someone I'm sure, but I don't know the first thing about batch scripting so I have to ask here instead!

At my work we have a bunch of directories set up like this:

code:
Reports
|--ACT
|----Customer1
|------2009
|------2010
|----Customer2
|------2008
|------2009
|------2010
|--NSW
|----Customer3
|------2010

Etc
I'm wondering if anyone knows how to write a batch file that would go through every Customer folder and create a new 2011 folder IF:
a) The 2010 folder exists AND
b) The 2010 folder IS NOT empty

Bonus points if you could make it remove any empty 2010 folders.


Sorry if this is an inappropriate place to post this request - I looked for the custom apps thread but it must've been archived or something?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
I'm sure someone will swoop in and gift you some script, but maybe you could share what you've tried yourself?

For example, the rmdir command will remove an empty directory, and Microsoft has a suggestion for testing for the presence of a directory. See what you can come up with!

baquerd
Jul 2, 2007

by FactsAreUseless

Woofington posted:

I would guess its running a linux distro...

Then you're looking for cron for simple scheduling. Type crontab -l at the prompt and see what you get.

Modern Pragmatist
Aug 20, 2008
What is the term that I need to use to search for different algorithms for adding and subtracting polygons by knowing the vertices of the different polygons. Basically what Photoshop does for selecting a region with say a box then "subtracting" another box region from it, or "adding" a oval region.

It is really easy if I discretize everything to take integer values and just add and subtract binary maps, but I really want a continuous solution.

I hope that makes sense.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Modern Pragmatist posted:

What is the term that I need to use to search for different algorithms for adding and subtracting polygons by knowing the vertices of the different polygons. Basically what Photoshop does for selecting a region with say a box then "subtracting" another box region from it, or "adding" a oval region.

It is really easy if I discretize everything to take integer values and just add and subtract binary maps, but I really want a continuous solution.

I hope that makes sense.

I think what you're looking for is boolean operations, Constructive Solid Geometry is an example of a 3D version of it.

Google gives me:

http://www.cgal.org/Manual/3.3/doc_html/cgal_manual/Boolean_set_operations_2/Chapter_main.html
http://www.cs.drexel.edu/~david/Classes/CS430/HWs/p214-weiler.pdf

Plinkey
Aug 4, 2004

by Fluffdaddy
Quick question.

Does anyone know a windows script/batch file command that will change the last accessed date on a file to a specified date/time?

Basically I need to be able to quickly update an entire directory of files/folders with new accessed dates so they won't be caught by the company's auto archiver. I'd like to be able to work it into a script that I can run ever month or so on folders that have documents that we can't afford to have picked up by the archiver (they are way too hard to get when archived), but I'd also like to have the date/time be somewhat random so that all the files don't have the exact same accessed date.

Thanks in advance.

raminasi
Jan 25, 2005

a last drink with no ice

Modern Pragmatist posted:

What is the term that I need to use to search for different algorithms for adding and subtracting polygons by knowing the vertices of the different polygons. Basically what Photoshop does for selecting a region with say a box then "subtracting" another box region from it, or "adding" a oval region.

It is really easy if I discretize everything to take integer values and just add and subtract binary maps, but I really want a continuous solution.

I hope that makes sense.

I've had to wrangle CGAL on Windows if you have to do that and run into any trouble.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Plinkey posted:

Quick question.

Does anyone know a windows script/batch file command that will change the last accessed date on a file to a specified date/time?

Basically I need to be able to quickly update an entire directory of files/folders with new accessed dates so they won't be caught by the company's auto archiver. I'd like to be able to work it into a script that I can run ever month or so on folders that have documents that we can't afford to have picked up by the archiver (they are way too hard to get when archived), but I'd also like to have the date/time be somewhat random so that all the files don't have the exact same accessed date.

Thanks in advance.

echo "" >> filename.ext or copy /b filename.ext +,, work for current time. For arbitrary times grab a Windows port of touch, maybe from unxutils.

Dead Pressed
Nov 11, 2009
This is probably too simple for this place (or the incorrect location, sorry!), but I have an excel macro question to ask of you all.

I'm working on a wedding list in excel, and there's some sorting functionality I'm trying to macro and assign to a big button for my fiancee. Basically, the list has these headers:

Lastname, family designation, head of household, firstname, party invite, party rsvp, wedding invite, wedding rsvp

Click here for the full 1104x137 image.


Basically, the goal is for the macro to sort last name first, then order members of different families with same name (ie, jones) by a numerical designation (jones 1, jones 2), then it will place heads of the households at the top of the list (for that specfic name) so they can appropriately be addressed in the invitations, then sorted lastly sorted alphabetically by first name. I've got it set up so we can also filter from the headers so that my fiancee and check off people who've gotten invites to the party/wedding, and then filter the list to see who needs what, and how many are coming, etc.

TLDR So, now the point. I can go through the sorting steps fine myself, and everything works how I intend. I then go to record the macro in excel, and it works, but as soon as more names are added, the macro does not work. It may work randomly after mashing the hotkeys a thousand times, or they may not. Does anybody any idea what may be happening?

*Edit* This is crossposted in the Small Excel Q thread. I didn't realize there was an up to date one, as the one in the megathread was dead. :(

Dead Pressed fucked around with this message at 23:28 on Jan 11, 2011

VirtuaSpy
Jul 26, 2002

OMG WTF FIREEEE!!
--- moved to Goons for Hire thread.

VirtuaSpy fucked around with this message at 20:43 on Jan 12, 2011

slotbadger
Jul 19, 2007
hey deadhead - take a bite of peach.
Quick (and no doubt ridiculously trivial) C# question from a non-C# developer:

I have a form. I click a button on that form and it creates another form. I need the "OK" button to be clicked on this form before the code continues. Looks something like this:

code:
Form2 myForm = new Form2();
if (myForm.ShowDialog() == DialogResult.OK)
{
     // Do stuff
}
Now, if I click "OK" on the form, it works fine. However, if I hit Enter/Return it doesn't work. The key listener is set-up properly, I just need to know what event to call / how to ensure ShowDialog() returns as DialogResult.OK.

Mr.Hotkeys
Dec 27, 2008

you're just thinking too much

slotbadger posted:

Now, if I click "OK" on the form, it works fine. However, if I hit Enter/Return it doesn't work. The key listener is set-up properly, I just need to know what event to call / how to ensure ShowDialog() returns as DialogResult.OK.

First, make sure whatever is getting focus when the form opens has the event listener set up for it as well. If the button is getting focus when the form opens but the listener is only set up to work for the form, it won't work.

And to return the correct result, just use the form's DialogResult property, and set it to whatever you want (DialogResult.OK in this case). That will return the desired result and close the form for you.

e: To clarify, setting DialogResult won't close it instantly, so follow it up with Close() if you want the form to close right then and there.

Mr.Hotkeys fucked around with this message at 09:19 on Jan 12, 2011

slotbadger
Jul 19, 2007
hey deadhead - take a bite of peach.

Mr.Hotkeys posted:

First, make sure whatever is getting focus when the form opens has the event listener set up for it as well. If the button is getting focus when the form opens but the listener is only set up to work for the form, it won't work.

And to return the correct result, just use the form's DialogResult property, and set it to whatever you want (DialogResult.OK in this case). That will return the desired result and close the form for you.

e: To clarify, setting DialogResult won't close it instantly, so follow it up with Close() if you want the form to close right then and there.

Ta. Did the trick, and I feel a bit stupid now. :)

For reference, I just added:
code:
this.DialogResult = DialogResult.OK;
this.Close();
to the method handling the OK button's click event.

Thanks!

slotbadger fucked around with this message at 09:33 on Jan 12, 2011

DholmbladRU
May 4, 2006
I was not really sure where to put this.

Anyways, I am about to complete my undergraduate degree in computer science. And am wondering if you all have any advice on where to gain leads on developer jobs.

Granted I will not be graduating until may, and many jobs posted online are looking for immediate hires. What I have done so far is contacted any company I have worked for in the past to inquire about full time opportunities, as well as applying online to a few larger contractors in the dc area.

spiritual bypass
Feb 19, 2008

Grimey Drawer
Have you asked all of your professors? Does your school have a career counselor? They can help.

indeed.com is my favorite job search site because it aggregates jobs from lots of sources.

csammis
Aug 26, 2003

Mental Institution

DholmbladRU posted:

I was not really sure where to put this.

Anyways, I am about to complete my undergraduate degree in computer science. And am wondering if you all have any advice on where to gain leads on developer jobs.

Granted I will not be graduating until may, and many jobs posted online are looking for immediate hires. What I have done so far is contacted any company I have worked for in the past to inquire about full time opportunities, as well as applying online to a few larger contractors in the dc area.

This thread has some Get A Job resources / suggestions / advice

mcw
Jul 28, 2005
What do you guys usually do for authentication / authorization with web apps and web services?

In the past, I've always created the auth scheme myself, and now I find myself wanting a more general-purpose solution: something that can be used to provide a single sign on regardless of what sort of application I'm developing. My background is not in system administration, so I've got a lot of research to do-- and as part of that, I'm hoping you folks might be willing to share your own opinions on the subject, particularly in regards to how you've solved this problem in your own work.

mr. unhsib
Sep 19, 2003
I hate you all.
Not sure if this belongs here or in the "Small Math Questions" thread, so I'll just ask it in both! :v:

Say I have a list of n jobs. A job has a start time and an end time (just say they're integers). I want to know if any of the jobs conflicts with any other (ie, is overlapping). It doesn't matter to me which job it is in conflict with which other job or how many other jobs - all I want is, for every job, a yes-no answer to the question "is there a conflict?".

Put a more computing science-y way, I have a collection of objects:

struct Job {
int start;
int end;
bool is_conflict;
};

Assuming start and end are defined, correctly set is_conflict for all these objects.

I'm having trouble coming up with a solution that isn't O(n^2) in the worst case.

nielsm
Jun 1, 2009



mr. unhsib posted:

I'm having trouble coming up with a solution that isn't O(n^2) in the worst case.

Sort them by start time. (O(n log n))

Then for each job, if the start time is smaller than the end time of the previous, those two conflict. (O(n))

O(n log n) + O(n) = O(n log n)

pseudorandom name
May 6, 2007

nielsm posted:

Sort them by start time. (O(n log n))

Then for each job, if the start time is smaller than the end time of the previous, those two conflict. (O(n))

O(n log n) + O(n) = O(n log n)

start: 1
end: 5

start: 2
end: 3

start: 4
end: 6

ToxicFrog
Apr 26, 2008


I suspect that if you revise the algorithm to "if the start time is earlier than the latest recorded end time" rather than just the end time of the previous event, it'll work (and still be O(nlogn)), but I don't have a proof.

nielsm
Jun 1, 2009



ToxicFrog posted:

I suspect that if you revise the algorithm to "if the start time is earlier than the latest recorded end time" rather than just the end time of the previous event, it'll work (and still be O(nlogn)), but I don't have a proof.

Yeah, oversight.

code:
class Job:
	def __init__(self, st, ed):
		self.start = st
		self.end = ed
		self.overlaps = False

jobs = [Job(1, 5), Job(4, 6), Job(10, 20), Job(2, 3), Job(7, 9)]

jobs.sort(lambda a, b: a.start - b.start)

prevend = None
prevjob = None
for j in jobs:
	if prevjob == None:
		prevend = j.end
		prevjob = j
	elif j.start <= prevend:
		j.overlaps = True
		prevend = max(prevend, j.end)
		prevjob.overlaps = True
	else:
		prevend = None
		prevjob = None

for j in jobs:
	print j.start, "->", j.end, j.overlaps and "(o)" or ""

python posted:

1 -> 5 (o)
2 -> 3 (o)
4 -> 6 (o)
7 -> 9
10 -> 20

Dransparency
Jul 19, 2006

MariusMcG posted:

What do you guys usually do for authentication / authorization with web apps and web services?

In the past, I've always created the auth scheme myself, and now I find myself wanting a more general-purpose solution: something that can be used to provide a single sign on regardless of what sort of application I'm developing. My background is not in system administration, so I've got a lot of research to do-- and as part of that, I'm hoping you folks might be willing to share your own opinions on the subject, particularly in regards to how you've solved this problem in your own work.

At my company we use a combination of OpenID and OAuth. OpenID is used for user accounts while OAuth is used for "system accounts" (i.e. application-to-application authentication) and actions taken on behalf of a user. Unlike many uses of OpenID on the web, we restrict the relying parties we develop to only accept authentication from our identity provider(s), similar to Google's suite of applications. Having the option for federated identities is nice because it allows us to segregate portions of our user-base that have conflicting identity requirements (e.g. one group needs to be self-service registration, another needs to have accounts manually provisioned and verified) into separate identity realms.

One of the biggest benefits we've seen from this approach is that many popular languages have open source libraries/clients already written for these protocols, so it's fairly straightforward for anyone in the company to interface with our service using their language of choice. Centralizing identity management has lots of benefits of its own since you solve common problems (e.g. attack prevention, account registration, email address confirmation, etc.) once, rather than for each application.

This solution has only been in place for about six months, so we haven't encountered any major architectural problems yet. One problem we have run into recently is handling authentication for applications that aren't browser-based. Since OpenID is a web protocol, there isn't an easy way to handle native apps without having the app circumvent some of the benefits of the protocol. If you need to support such applications, you might want to look at alternative (or at least additional) authentication mechanisms.

tef
May 30, 2004

-> some l-system crap ->

mr. unhsib posted:

Put a more computing science-y way.:

I have an interval graph, and I want to know if it is proper.

iirc you should be able to find the maximum independent set (largest set of non-overlapping jobs) in nlogn too.

(also this is used for dna sequence similarity :science:)

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

ToxicFrog posted:

I suspect that if you revise the algorithm to "if the start time is earlier than the latest recorded end time" rather than just the end time of the previous event, it'll work (and still be O(nlogn)), but I don't have a proof.
If those are ever not the same thing you would have already detected an overlap, as a non-overlapping sequence must have monotonically increasing end times when sorted by start times. The originally stated algorithm handles pseudorandom name's example correctly.

pseudorandom name
May 6, 2007

The question was "Does this specific job conflict with any other job in this set?" not "Does at least one job in this set conflict with another job?"

mr. unhsib
Sep 19, 2003
I hate you all.

ToxicFrog posted:

I suspect that if you revise the algorithm to "if the start time is earlier than the latest recorded end time" rather than just the end time of the previous event, it'll work (and still be O(nlogn)), but I don't have a proof.

Yup, I didn't see this step. Ugh, stupid. Thanks all.

Edit - I just stood at a whiteboard and spent 10 minutes coding an O(N^2) algorithm for this problem in C++ at a job interview, :lol:

mr. unhsib fucked around with this message at 07:03 on Jan 13, 2011

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

pseudorandom name posted:

The question was "Does this specific job conflict with any other job in this set?" not "Does at least one job in this set conflict with another job?"
"It doesn't matter to me which job it is in conflict with which other job or how many other jobs" quite explicitly says the opposite. Of course, he does go on to contradict that so I guess I should not assume that when someone restates a problem five times that they will all say the same thing.

mr. unhsib
Sep 19, 2003
I hate you all.

Plorkyeran posted:

"It doesn't matter to me which job it is in conflict with which other job or how many other jobs" quite explicitly says the opposite. Of course, he does go on to contradict that so I guess I should not assume that when someone restates a problem five times that they will all say the same thing.

Dangling modifier error. I meant that i don't care how many other jobs a given job is in conflict with.

1337JiveTurkey
Feb 17, 2005

A more impractical but neat in a conceptual sense method would be to sort the jobs by start time and then create an array twice as long as the number of jobs. Fill the array with the start time of the first job, then the end time, then the start time of the second and so forth. If you sort that array with an insertion sort, the number of exchanges you make should equal the number of conflicts.

Jam2
Jan 15, 2008

With Energy For Mayhem
I wrote this code to convert RGB color to HSI as a first programming project. It's slow as poo poo. I'm told it's because of all the If and Which statements, etc. and that I should look into alternatives. Knowing nothing about computer science, I don't know what a replacement would look or feel like. I don't grasp the concept that there exists something different that is faster and serves the same purpose. What is the substitute for loops like For and If and Which?

code:
RGBconvertHSI[dir_] := 
 Module[{img, imgrawdata, imgrgb, r, g, b, m, n, rgb, intensity, summ,
    r1, g1, b1, r1g1b1, min1, saturation, hue},
  img = Import[dir];
  {n, m} = ImageDimensions[img];
  imgrawdata = ImageData[img];
  r = ConstantArray[0, {m, n}];
  g = ConstantArray[0, {m, n}];
  b = ConstantArray[0, {m, n}];
  If[ImageChannels[img] == 1,
   For[j = 1, j < n + 1, j++,
    For[i = 1, i < m + 1, i++,
     r[[i, j]] = g[[i, j]] = b[[i, j]] = imgrawdata[[i, j]]
     ]]];
  If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     r[[i, j]] = ImageData[Extract[ColorSeparate[img], 1]][[i, j]]]]];
  If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     g[[i, j]] = ImageData[Extract[ColorSeparate[img], 2]][[i, j]]]]];
  If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     b[[i, j]] = ImageData[Extract[ColorSeparate[img], 3]][[i, j]]]]];
  rgb = Table[
    Table[{r[[i, j]], g[[i, j]], b[[i, j]]}, {j, 1, n}], {i, 1, m}];
  summ = Total[rgb, {3}];
  intensity = 
   summ/3;(*seems more efficient than looking for rgb values again*)
  r1 = ConstantArray[0, {m, n}];
  For[j = 1, j < n + 1, j++, For[i = 1, i < m + 1, i++,
    If[intensity[[i, j]] == r[[i, j]], r1[[i, j]] = 1/3, 
     r1[[i, j]] = r[[i, j]]/(r[[i, j]] + g[[i, j]] + b[[i, j]])]]];
  g1 = ConstantArray[0, {m, n}];
  For[j = 1, j < n + 1, j++, For[i = 1, i < m + 1, i++,
    If[intensity[[i, j]] == r[[i, j]], g1[[i, j]] = 1/3, 
     g1[[i, j]] = g[[i, j]]/(r[[i, j]] + g[[i, j]] + b[[i, j]])]]];
  b1 = ConstantArray[0, {m, n}];
  For[j = 1, j < n + 1, j++, For[i = 1, i < m + 1, i++,
    If[intensity[[i, j]] == r[[i, j]], b1[[i, j]] = 1/3, 
     b1[[i, j]] = b[[i, j]]/(r[[i, j]] + g[[i, j]] + b[[i, j]])]]];
  r1g1b1 = 
   Table[Table[{r1[[i, j]], g1[[i, j]], b1[[i, j]]}, {j, 1, n}], {i, 
     1, m}];
  min1 = Map[Min, r1g1b1, {2}];
  saturation = 1 - 3*min1;
  hue = ConstantArray[0, {m, n}];
  For[j = 1, j < n + 1, j++, For[i = 1, i < m + 1, i++,
    Which[saturation[[i, j]] == 0, hue[[i, j]] = 0, 
     g1[[i, j]] >= b1[[i, j]], 
     hue[[i, j]] = 
      ArcCos[(.5 ((r1[[i, j]] - g1[[i, j]]) + (r1[[i, j]] - 
               b1[[i, j]])))/(((r1[[i, j]] - 
                g1[[i, j]])^2 + (r1[[i, j]] - 
                b1[[i, j]]) (g1[[i, j]] - b1[[i, j]]))^(1/2))]*180/Pi,
      g1[[i, j]] < b1[[i, j]], 
     hue[[i, j]] = 
      360 - ArcCos[(.5 ((r1[[i, j]] - g1[[i, j]]) + (r1[[i, j]] - 
                b1[[i, j]])))/(((r1[[i, j]] - 
                 g1[[i, j]])^2 + (r1[[i, j]] - 
                 b1[[i, j]]) (g1[[i, j]] - b1[[i, j]]))^(1/2))]*180/
         Pi]]];
  Print["Source Image", img];
  Print["Hue=", N[hue, 2] // MatrixForm];
  Print["Saturation=", N[saturation, 2] // MatrixForm];
  Print["Intensity=", N[intensity, 2] // MatrixForm];
  									]

mr_jim
Oct 30, 2006

OUT OF THE DARK

You have multiple If statements with exactly the same test, and exactly the same loop statement inside. Just combine them.

For example, instead of:
code:
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     r[[i, j]] = ImageData[Extract[ColorSeparate[img], 1]][[i, j]]]]];
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     g[[i, j]] = ImageData[Extract[ColorSeparate[img], 2]][[i, j]]]]];
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     b[[i, j]] = ImageData[Extract[ColorSeparate[img], 3]][[i, j]]]]];
try using:
code:
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     r[[i, j]] = ImageData[Extract[ColorSeparate[img], 1]][[i, j]]]]];
     g[[i, j]] = ImageData[Extract[ColorSeparate[img], 2]][[i, j]]]]];
     b[[i, j]] = ImageData[Extract[ColorSeparate[img], 3]][[i, j]]]]];

Jam2
Jan 15, 2008

With Energy For Mayhem

mr_jim posted:

You have multiple If statements with exactly the same test, and exactly the same loop statement inside. Just combine them.

For example, instead of:
code:
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     r[[i, j]] = ImageData[Extract[ColorSeparate[img], 1]][[i, j]]]]];
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     g[[i, j]] = ImageData[Extract[ColorSeparate[img], 2]][[i, j]]]]];
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     b[[i, j]] = ImageData[Extract[ColorSeparate[img], 3]][[i, j]]]]];
try using:
code:
If[ImageChannels[img] > 1, 
   For[j = 1, j < n + 1, j++, 
    For[i = 1, i < m + 1, i++, 
     r[[i, j]] = ImageData[Extract[ColorSeparate[img], 1]][[i, j]]]]];
     g[[i, j]] = ImageData[Extract[ColorSeparate[img], 2]][[i, j]]]]];
     b[[i, j]] = ImageData[Extract[ColorSeparate[img], 3]][[i, j]]]]];

I wanted to do this, but didn't know it was syntactically legal. Thanks. I'll replace the other areas with similar code. Anything else?

Is there some sort of complete replacement for For/If language?

Jam2 fucked around with this message at 02:02 on Jan 15, 2011

tripwire
Nov 19, 2004

        ghost flow

Jam2 posted:

Is there some sort of complete replacement for For/If language?

:confused:

What

Jam2
Jan 15, 2008

With Energy For Mayhem

tripwire posted:

:confused:

What

I dunno either man. In computing, when I'm told there's a better/faster way to do something, I don't attempt to disprove it, especially when my algorithm takes several minutes to an hour to process large 1920x1200 images. I always feel like there must be a better way.

raminasi
Jan 25, 2005

a last drink with no ice

Jam2 posted:

I wanted to do this, but didn't know it was syntactically legal. Thanks. I'll replace the other areas with similar code. Anything else?

Is there some sort of complete replacement for For/If language?

Some languages have constructs that allow you to specify program logic at a "higher level," in the sense that you describe more what the program is doing than how the program is doing it. (This was what I thought of when I read your question, anyway.) You won't necessarily get any better performance - some people just find it easier/more efficient/more fun to work this way.

Adbot
ADBOT LOVES YOU

mr_jim
Oct 30, 2006

OUT OF THE DARK

Jam2 posted:

I wanted to do this, but didn't know it was syntactically legal. Thanks. I'll replace the other areas with similar code. Anything else?

Is there some sort of complete replacement for For/If language?

I'm not sure if it is syntactically legal, or if you need to group the statements together with braces or Begin/End. I'm not familiar with whatever language that code is in. However, regardless of language, running what is essentially the same nested loop multiple times is likely to be less efficient that doing everything in a single nested loop.

Loops and conditional statements are fundamental to most programming languages, so you aren't going to find something to replace them. The goal is to compose them correctly and efficiently to solve the problem at hand.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply