I am having problems converting XML data into the appropriate data types using a function.
I have read in an XML file using XmlParse().
Within that there is an array which I loop around. <Cfloop array=#i.Task# index="t">
My understanding is that the items in this array are XML text. I can display all the items with CFoutput no problem. One item in the array (BaseLineColor) is a colour. #t.BaseLineColor# However this colour value is a single decimal integer number of varying length. I have worked out the maths to convert this decimal number into R,G,B decimal values. All good so far.
The problem is that if I try mathematical functions on BaseLineColor, then I get:
The value ?xml version="1.0" encoding="UTF-8"? BaseLineColor 255 /BaseLineColor cannot be converted to a number.
So OK I have tried a few methods to try and convert BaseLineColor to an integer but nothing works. Val() doesn't work. In fact I can't seem to convert it into any datatype.
For example, here is me trying to make it a string - same error:
<cfscript>
Strbaselinecolor=toString(t.BaseLineColor);
rdec=floor(Strbaselinecolor / 65536);
gdec=floor((Srtbaselinecolor - rdec * 65536)/256);
bdec=floor(Strbaselinecolor - rdec * 65536 - gdec * 256);
writeOutput("#t.baselinecolor#: #Strbaselinecolor# red #rdec#, green #gdec#, blue #bdec#")
</cfscript>
What function should I be using? Am I supposed to be pre-processing the XML in some way before I can refer to some of these values as integers?
There are a lot of values in the XML data which are numbers (some integers and some floating point numbers) and so it is not just about these items that are colours but a more general problem with using any XML data that is not text. I have tried to find some reference material on this but have not found anything relevant so far. Yet I'm guessing this is a common issue when reading in XML files.
Thanks in advance for any help.
The error message is correct. The code is trying perform mathematical operations on something that is not a number, despite the fact that it may appear to be one in a browser... You're probably getting tripped up by how browsers handle tag based code like xml.
This code (incorrectly) shows the value of t.BaseLineColor as a simple number 255
<cfscript>
t = xmlParse('<?xml version="1.0" encoding="UTF-8"?><BaseLineColor>255</BaseLineColor>');
writeOutput(t.BaseLineColor);
</cfscript>
Runnable Example
However, using a browser's "Inspect Element" tool, reveals the value is actually an xml string. Since browsers treat anything enclosed in < and > as html tags, which aren't rendered, only the number 255 is visible on screen.
writeDump() is more helpful here. It shows t.BaseLineColor as an xml node, and it's value is accessible through the xmlText attribute.
That simple value can be used in mathematical operations.
<cfscript>
t = xmlParse('<?xml version="1.0" encoding="UTF-8"?><BaseLineColor>255</BaseLineColor>');
result = t.BaseLineColor.xmlText / 65536 ;
writeOutput( result );
</cfscript>
Runnable Example
Related
I'm a bit confused here..
I'm trying to create a field with number and binding it into ng-model, but when I input this value
10000000000000000000000
It gets me 1e+22 on the model result, how can I make it as number not this string when I input lot of 0 behind.
Hopefully somebody here giving me 10000000000000000000000 then it should returns 10000000000000000000000 on the ng-model.
https://codepen.io/anon/pen/NaxoXJ
Thank you
How can I make it as number not this string when I input lot of 0 behind.
It's not a string, it's a number displayed using the scientific notation. Javascript uses this notation for big numbers. For example, in JS, this king of statement is valid :
var i = 1e+22;
Instead of using {{test}} to display your value, call a function to format the number correctly (the result will be a string and not an number).
This post explains how to print a number wihout using the scientific notation.
Updated codepen
To get a consistent look and feel of both input and output views I am trying to use an disabled input element to display model data/values.
The value is a calculated temperature value and has several decimal digits. Since that does not make sense from an engineer's point of view I want to limit the displayed decimal digits to a certain amount (let's say two digits, the displayed value does not need to be rounded).
Example:
calculated value: 123.123456
value to display: 123.12
I read around the Internet and found many suggestions using input's step attribute like
step=".01"
to limit the decimal digits. There seem to be many people doing it that way, but it does not work for me.
I think view and data model need to kept separated so adapting the model data (like converting the values to strings or using toFixed()) does not seem to be a nice solution. The view should be able to format the data itself, not changing the data model and should have reading access in this case only.
There is a filter for doing this when accessing model data through the {{ }} notation. But this does not seem to be applicable straight out of the way.
So, do you have any suggestions about limiting the decimal numbers?
For the sake of investigation and in order to provide a working sample code I created a Pen.
I am having some trouble manually creating a histogram of intensity values from a grayscale image. Below is the code that I am using the create the bins for the plot that I want to create. The code works fine for every bin except for the last two. For some reason if the intensity is 254 or 255 it puts both values into the 254 bin and no values are accumulated in the 255 bin.
bins= zeros(1,256);
[x,y]=size(grayImg);
for i = 1:x
for j = 1:y
current = grayImg(i,j);
bins(current+1) = bins(current+1) + 1;
end
end
plot(bins);
I do not understand why this behavior is happening. I have printed out the count of 254 intensities and 255 intensities and they are both correct. However, when using the above code to accumulate the intensity values it does not work correctly.
Edit: Added the image I am using, the incorrect graph(the one I get with above code), and the correct one
A. The first problem with your code is the initial definition of bins. It seems that you come from C or somthing like that, but the definition should be- bins=zeros(1,256);
B. The second point is that you don't need the nested loop, you have a matlab function especially for that:
bins=hist(grayImg(:),1:256); % now, you don't need the pre-definition for 'bins'.
plot(bins);
C. Try to use functions like bar or imhist or hist(grayImg(:)), it may save you all this, and give a nice plot.
I have an image that I'd like to programmatically position on an RDLC based on the X and Y values from the database. I originally thought I could just apply an expression to the Left and Top properties of the Location property, however it doesn't seem like there's an option to do that.
Is there anything I can do?
EDIT:
Fortunately the padding property allows expressions, however it seems I have another issue on my hands.
Here's my code for the "Left" property within the "Padding" property group.
=((Sum(Fields!intDessinX.Value, "dsRapport_uspReportCommandeInhumation") * 2.54) / 96) & "cm"
Essentially I'm converting the intDessinX value from the database from pixel to cm using the formula "cm = (pixel * 2.54) / 96" and finally appending "cm" to the end of the expression.
This does not work. I've done some research and can't seem to find how to take the value from a dataset and translate it into a measurement.
Does anyone know how to do this?
Thanks,
Mikael
Solved!! Since we're developing the website in French we had previously set the culture to "fr-CA" and this causes the decimal character to be replaced by a comma character.
As such, when it came time for the reporting engine to evaluate the value (with the comma), it wasn't positioning my image as it simply didn't understand that the value was in fact numeric.
I'm trying to write a neural network that (after being properly trained) identifies certain road signs and returns a different output for each type of sign.
Before I started to train my network, I noticed on the pybrain website that their datasets are always an array of values, each entry containing an input and a target. The images I have for my NN have been converted to grayscale pixel data (a simple array of numbers). To train each set of data, do I need to somehow add a target value for each pixel? And if so, how would I go about doing that?
QUICK ANSWER
No, you don't need target for every single pixel, you treat pixels from single image as your input data and you add target to that data.
LONG ANSWER
What you trying to do is to solve classification problem. You have image represented by array of numbers and you need to classify it as some class from limited set of classes.
So lets say that you have 2 classes: prohibitions signs (I'm not native speaker, I don't know how you call signs that forbid something), and information signs. Lets say that prohibition signs is our class 1 and information signs is class 2.
Your data set should look like this:
([representation of sign in numbers], class) - single sample
After that, since it's classification problem, I recommend using _convertToOneOfMany() method of DataSet class, to convert your targets into multiple outputs.
I've answered similar question here, go check it out.