maskedTextBox in windows form application - winforms

In windows form application, C# using Visual Studio 2012
My mask is 0.00 but when I enter 3.00 it consider just 3 not 3.00
and also when enter 3.30 it consider 3.3
but if I enter 3.01 then this value being considered.
problem is I want that it consider last zero's also.
in form designer code:
this.maskedTextBox1.Location = new System.Drawing.Point(402, 121);
this.maskedTextBox1.Mask = "0.00";
this.maskedTextBox1.Name = "maskedTextBox1";
this.maskedTextBox1.PromptChar = '-';
this.maskedTextBox1.Size = new System.Drawing.Size(31, 22);
this.maskedTextBox1.TabIndex = 23;
this.maskedTextBox1.ValidatingType = typeof(System.DateTime);
this.maskedTextBox1.MaskInputRejected += new
System.Windows.Forms.MaskInputRejectedEventHandler(this.maskedTextBox1_MaskInputRejected);

The Mask property applies to the format displayed in the Maskedit and to the characters that can be typed. It doesn't automatically format the Text for you.
If you want to display a string with the format required you need to convert the user typed text to a valid decimal and then use composite formatting to prepare a string that display the double as you wish
double d = Convert.ToDouble(maskedTextBox1.Text)
Console.WriteLine(string.Format("{0:N2}", d));

Related

How to Get specific data drom text in Octave

I have a problem loading data from text file in Octave.
My text file looks like this:
# Created by Octave 5.2.0, Wed May 05 16:07:02 2021 GMT <unknown#DESKTOP-HEVT6O6>
# name: x
# type: matrix
# rows: 1
# columns: 3600
4.8899999999999997 4.9000000000000004 4.9000000000000004 4.9100000000000001 4.9299999999999997 4.9249999999999998 ...
I need to load those float numbers in one matrix and plot them in time domain.
My code so far:
fs = 360;
Ts = 1/fs;
d = fileread('ecg.txt');
data = regexp(d(1,136:62328),' ','split');
data = str2double(data);
ed = length(data);
t = linspace(0,Ts,ed - 1);
figure(1)
plot(t,data(1,2:ed))
So My question is if there is another way to do it or if there is a better way to do it.
Your file is in Octave’s text data format. This is the default file format when saving variables to file with save. That is, that text file was saved in Octave using save ecg.txt x. The Octave command load ecg.txt will load the file, and re-create the x variable just like it was when it was saved.
Thus, to plot your data, just do
load ecg.txt
plot(x)

What strategy can I use to OCR Magic the Gathering corner text?

I need to recognize the text in the bottom left corner on Magic the Gathering paper cards (last design). Here an example:
If the text is like this
I want to retrieve the following text:
198/280 U
M20 EN
(I don't need the card author name - Lake Hurwitz in this example)
What OCR library can I use? I've tried with Tesseract without any tuning but the results are not correct. Any advice or link to a project that already does this stuff?
You can make it with tesseract (3.04.01) by sanitizing your image a bit
like in below code
import numpy as np
import cv2
def prepro(zone, prefix):
filename = 'stackmagic.png'
oriimg = cv2.imread(filename)
#keep the interesting part
(a,b,c,d) = zone
text_zone = oriimg[a:b, c:d]
height, width, depth = text_zone.shape
#resize it to be bigger (so less pixelized)
H = 50
imgScale = H/height
newX,newY = text_zone.shape[1]*imgScale, text_zone.shape[0]*imgScale
newimg = cv2.resize(text_zone,(int(newX),int(newY)))
#binarize it
gray = cv2.cvtColor(newimg, cv2.COLOR_BGR2GRAY)
th, img = cv2.threshold(gray, 130, 255, cv2.THRESH_BINARY);
#erode it
kernel = np.ones((1,1),np.uint8)
erosion = cv2.erode(img,kernel,iterations = 1)
cv2.imwrite(prefix+'_ero.png', erosion)
cv2.imshow("Show by CV2",erosion)
cv2.waitKey(0)
prepro((16,27, 6,130), 'upzone')
prepro((27,36, 6,130), 'downzone')
from your cropped image
you get
the upper part:
and the lower part:
and tesseract does seem to be able to extract
xx$ tesseract upzone_ero.png stdout
198/ 280 U
xx$ tesseract downzone_ero.png stdout
M20 ~ EN Duluu Hun-nu
Notice that we fail to extract Luke, but hopefully you were not interested in him/it :)
There are other tools but that'd be advertising stuff and be subjective..

matlab assigning text file data to age and gender

Okay so my assignment is for an engineering project and I have talked to my teacher many times but without much success. the code reads data that comes from a rotary encoder in a text file. The question I have is how do I make two sets of arrays with age and gender and link it to each text file thats read in. For example the first text file comes from a girl that is 10; that spun a crank and output data to a text file. How do i code so that someway i can assign the first text file to an age and gender? Heres my code so far any help is appreciated.
%% ME 208 Project Group 21
clear; close all; clc;
%Constants
dt=.1;
%Translate Data
mass = 10; %values are in units of Kilograms
radius = 1; %values are in units of meters
inertia = mass*radius^(2);
for ii=1:2
%File Name Variable
filename=['sub_' num2str(ii) '.txt'];
%Data is Collected
Data1=dlmread(filename,'\t',0,0);
%Times for data
t1=dt:dt:length(Data1)*dt;
%Vel
[ang_vel1, ang_acc1]=dxdt_d2xdt2(Data1,2,dt);
torq1 = inertia*ang_acc1;
%Calculations of parameters
meanrt1(ii) = rms(torq1);
maxrt1(ii) = max(torq1);
end
%Plot
figure(1);plot(t1,torq1,t2,torq2); grid minor;

How to make ISO8601 produce Hebrew day of the year, week of the year?

Can someone think of a way to calculate the Day-of-the-Year and Week-of-the-Year for the Hebrew calendar? I'm using ISO 8601 which can return the Hebrew year, month, day of the month and day of the week. I'm trying to write re-usable code to calculator any Torah portion (Parsha).
Take a look at the hebcal command to do this. There are also ports for JavaScript (shameless plug, it was written by me), Java, and Perl.
This is easy if you can use Java. My library Time4J enables the features you want (in Hebrew calendar):
PlainDate iso8601 = Iso8601Format.parseDate("2018-03-16");
HebrewCalendar hc = iso8601.transform(HebrewCalendar.axis());
int hyear = hc.getYear();
HebrewMonth hmonth = hc.getMonth(); // obtains an enum
int hdayOfMonth = hc.getDayOfMonth();
Weekday hdayOfWeek = hc.getDayOfWeek(); // obtains an enum
int hdayOfYear = hc.getDayOfYear();
int weekOfYear =
hc.get(
CommonElements.weekOfYear(
HebrewCalendar.axis(),
HebrewCalendar.getDefaultWeekmodel()
)
);
System.out.println("year=" + hyear); // 5778
System.out.println("month=" + hmonth); // ADAR_II (technical result, see next line)
System.out.println(
"month=" + hmonth.getDisplayName(Locale.ENGLISH, hc.isLeapYear())); // Adar
System.out.println("day-of-month=" + hdayOfMonth); // 29
System.out.println("day-of-week=" + hdayOfWeek); // FRIDAY
System.out.println("day-of-year=" + hdayOfYear); // 207
System.out.println("week-of-year=" + weekOfYear); // 30
There are many more features, for example taking into account start of day in the evening of previous day (including astronomical calculations of sunset) or hebrew biblical clock time or different numbering schemes for months etc.

Way to assign multiple files to set variable names?

Is there a way to assign file names to set varibles using a GUI? Say I have 6 file sets which contain 4 colors each (blue, green, nir, red). There are 24 files in total, so i'd need 24 variables. And I want the set varialbes to be something like
blue1
green1
nir1
red1
blue2
green2
nir2
red2
etc...
Currently I'm trying to use GUIDE to creat a custom GUI that will allow the user to select the files they wish and have them assigned to certain variables. I am thinking something along the lines of having 24 popupmenus that are attached to a file directory and allows the user to select which file they want, and then it will assign that file and it's path to a variable (blue1 for example) I also want 24 check boxes to associate with an if statement
Let's say popupmenu1 is associated with the variable blue1 and checkbox1
if checkbox1 == checked
do import
elseif checkbox1 == unchecked
fill with zeros
I have the basic frame of the GUI created, I am just unclear on how to apply the file select and then associate the if statements, etc...
If you know the variable files in advance, it's bad practice (look also here and here) to use string defined variable names like this:
var1name = 'blue';
var2name = 'red';
% etc.
% load data
datablue=rand(4,1);
datared =rand(4,1);
% assign
eval([var1name '1 = datablue(1);']);
eval([var2name '1 = datared (1);']);
% etc.
eval([var1name '2 = datablue(2);']);
eval([var2name '1 = datared (2);']);
% etc
It's much easier and better to just use an ordinary array, given the variable name is not changing or application dependend, which in my example I already have as datablue and datared.
Another option if you'd like user defined variable names is to use an array of structs:
var1name = 'blue';
var2name = 'red';
sample(1).(var1name) = datablue(1);
sample(1).(var2name) = datared (1);
% ...
sample(2).(var1name) = datablue(2);
sample(2).(var2name) = datared (2);
Try some of these out, and only if you have a very good reason, resort to eval!
for k = 1:6
blue(k) = sprintf('blue%d', k);
green(k) = sprintf('green%d', k);
nir(k) = sprintf('nir%d', k);
red(k) = sprintf('red%d', k);
end
This will create the variable names for you. Then you can use assignin (i believe) or eval to set the values to the variable names.

Resources