Pj Hughes

Greenhorn
+ Follow
since Mar 24, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Pj Hughes

Ok sorry about that!

I wasnt sure where to post this as for me it will be the first time i really get into java and java graphics.

thanks for the help!
9 years ago
Hi there

thanks for the quick reply and thanks for confirming my suspicion that this is possible.

I am aware that you can integrate java and matlab thanks to Yair Altmans website Undocumented Matlab Java

I can see from this site that it is possible to include JFrames etc in a matlab UI - exactly what i would want.

My main question is how to go about the actual Java code and if the functionality was there to load a 3D medical image and overlay the mask and then modify the mask.

How complex is this and for someone with relatively no experience is it even possible for me to write this in a reasonable (approx 1 month) timescale?

Thanks again!
9 years ago
Hi all

I have not written in Java for a long time and have the following problems/ideas:

I have written a Matlab Gui to do some image segmentation filtering etc.

The next step is to overlay the images and to modify the image mask using a paintbrush tool (similar to the functionality found in ITK-SNAP).

My first idea was to use matlabs poor equivalents of listeners etc. but i just cannot see anyway to apply it to images that are overlaid and also the speed is poor.

My next idea was to write a small java app to do this and then to have that run in matlab when a button is pushed in the gui, and when it shuts down the data is passed ot the matlab ui handles structure.

So in essence my question is in two parts:

Can i write a java app to load in images, overlay and then allow me to modify the mask (add to and erase parts) and adjust the contrast of the image below

can this java app then be used in a matlab UI?

Thanks for any advice/tips in advance!
9 years ago
I have also managed to fix the Array out of bounds issue. I forgot to resize the array after increasing the file size.

I am now getting the same answer for each equation? can somebody point out my error? any advice will be much appreciated.

the output is:
49+62*61-36
15.666666666666668
4/64
15.666666666666668
(53+26)
15.666666666666668
0*72
15.666666666666668
21-85+75-85
15.666666666666668
90*76-50+67
15.666666666666668
46*89-15
15.666666666666668
34/83-38
15.666666666666668
20/76/14+92-15
15.666666666666668
5*10/3-1
15.666666666666668

instead of:

49+62*61-36
3795
4/64
0.0625
(53+26)
79
0*72
0
21-85+75-85
-74
90*76-50+67
6857
46*89-15
4079
34/83-38
-37.5903614458
20/76/14+92-15
77.0187969925
5*10/3-1
15.666666666666668
11 years ago
Managed to get the brackets issue resolved by removing them from the hashmap declaration.
11 years ago
Hi

I have managed to get it working for the file with one equation in it.

I am now getting the following error when trying to read in more than one line?

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at uk.ac.shef.dcs.com262.coa10pjh.TestClass.main(TestClass.java:146)


Is there a way to make it do it line by line?

THE CHANGE MADE WAS TO MOVE THE END BRACKET OF THE WHILE STATEMENT TO LINE 101

UPDATED VERSION JUST IN CASE

11 years ago

Campbell Ritchie wrote:What algorithm are you using to determine how to change to RPN (I presume that means Reverse Polish Notation, which I usually call postfix)? How do you turn 1 + 2 × 3 into 1 2 3 × +?



Hi

yes it is postfix I want the expression in.

I am using the shunting yard algorithm.

11 years ago
Hi

I have managed to get a calculator program written although it is not working properly at the moment. For this purpose I have written my own stack and array classes.

I have made a file with only one equation in it:
49+62*61-36

and the program output should be - the second line should be in RPN format:
49+62*61-36
[49+62*61-36]
3795

But I am currently getting:
49+62*61-36
[36]
36.0

I don't see why it is only keeping the last token? all code is shown below. Any help will be much appreciated.

My arraylist class


my stack class


the class where the calculations happen.

11 years ago
Hi thanks for that.

I want it to be able to read in an unknown number of expressions from a file. it will then store the numbers, operands etc before converting and printing out the result.

I hope this is ok as an explanation.

Thanks again
11 years ago
Hi thanks for the information.

So before I attempt the RPN I will have to pass my list to the shunting yard class?

Also would I be able to implement a stack using linked lists?

Cheers
11 years ago
my new list of classes are:

List class
Node class
Shunting yard class
Main class
Main includes the reverse Polich notation, filereader and tokenizer.

My question now is how would i link main to the shunting yard? I was told I should create a list of objects which will be numbers, operands and brackets. Thanks again
11 years ago

Anayonkar Shivalkar wrote:Hi Pj Hughes,

Welcome to CodeRanch!

Firstly, please ShowSomeEffort. What have you tried till now? Is there any specific step where you are stuck?

Secondly, it would be better to provide links to some not-so-obvious things from your post (e.g. what is Polish Notation, what is shunting yard algorithm etc.).

Also, I would suggest to work with paper and pencil(or pen) first - that is - be very clear about the logic of your code and data structures you need for the same.

I hope this helps.



Hi well my first thought were the following classes:

a filereader class
a main class which does the conversion
a class to consider the numbers and operators
a main class to deliver the answers and tie everything together.

the main step where i am stuck is why would i have to represent the numbers and operators as objects when i could just convert the string straight away?

some links for the algorithms:
http://en.wikipedia.org/wiki/Shunting-yard_algorithm
http://en.wikipedia.org/wiki/Reverse_Polish_notation

12 years ago
I am attempting to create a calculator using a class hierarchy - the basic function will be:

Convert the String representation into a list of Tokens Convert the List of Tokens into Polish Notation Calculate the result on the basis of Polish Notation I also need to represent objects -

numbers operators and brackets.

Following this i need to convert to polish notation - using a shunting yard algorithm and then compute the answer.

I am ok with understanding the shunting yard but am unsure as to the class hierarchy part.

The precedence is - Addition and Subtraction have a precedence of 2, and Multiplication and Division have a precedence of 3.

I am assuming i need a filereader class and also classes to handle the different objects.

I also need help in creating my own stacks and queues.

I will be reading my equations in from a file with one calculation per line.

I am not supposed to use the java.utils

Could anyone point out a good hierarchy to rpresent the three objects and why i need to do it? i assmed i could just have a method to change the string to RPN straight away?
Thanks
12 years ago
managed to get it working thanks for all the help
12 years ago

Rob Spoor wrote:Don't use == for comparing Strings, use the equals method.



Hi I have tried that and i get Error:null when i run the program. everything works except the file reader now. here is my latest attempt at it:

12 years ago