why code page's characters doesn't have continuous hex value and how their hex value get generated? - unicode

Let's take Code page 37 for example
https://en.wikipedia.org/wiki/Code_page_37
I have two questions:
Q1-what does horizontal 0.. F and vertical 0x .. Fx stand for? I mean, for example how does 2F is in the (1, 6x)?
Q2- why characters are not continuous in term of hex value? for example if you start from 6_ as y axis and read from left to right, we have 2D, 2F, C2, C4, C0, C1 ..., should it be sth like C0, C1, C2 ..., which is more straight forward?

Related

What is a Mat-lab function for « If-in »?

Problem statement: Provide a function that does the following: c1) two vectors D1 and D2 have 7 elements each, then form the division between the corresponding components of each vector and assign the result to a vector name D3, placing a statement that avoids division by zero (i.e., does not divide if element to denominator is null);
The idea of the problem, is to set an error message whenever one of the elements of vector D2 is equal to 0.
My attempt:
D1 = [d1 d2 d3 d4 d5 d6 d7]
D2= [d21 d22 d23 d24 d25 d26 d27]
for i= 1:length(D1)
if 0 in D2
fprintf(‘error: division by 0/n’)
else
D3=D1./D2
end
I don’t know if the “if-in” structure exists in Matlab. If it doesn’t, what could be an equivalent?
Thanks in advance!!!
One way to avoid any division by zero is to modify D2 by replacing any 0 with nan. Divisions by nan produce nan, so it's easy to tell which division would have caused a problem by simply inspecting the resulting vector D3. Moreover, almost all Matlab's functions are able to handle nans nicely (i.e. without crashing) or can be instructed to do so by setting some option.
What I've just described can be accomplished by using logical indexing, as follows:
% Definition of D1 and D2
D1 = [d1 d2 d3 d4 d5 d6 d7]
D2 = [d21 d22 d23 d24 d25 d26 d27]
% Replace 0s with NaNs
D2(D2==0) = nan;
% Perform the divisions at once
D3 = D1./D2 ;
For more details on logical indexing, look at the relevant section here.
As the OP requests a function that does the job, here's a possible implementation:
function D3 = vector_divide(D1, D2)
% Verify that vectors are numeric
% and have the same dimensions
if isnumeric(D1) & isnumeric(D2) &...
(size(D1,1) == size(D2,1)) &...
(size(D1,2) == size(D2,2))
% replace 0s with NaNs
D2(D2==0) = nan;
% Perform the divisions at once
D3 = D1./D2 ;
else
disp('D1 and D2 should both be numeric and have the same size!');
D3 = [];
end
Error handling in case of non-numeric arrays or size mismatch might vary depending on project requirements, if any. For instance, I could have used error (instead of disp) to display a message and terminate the program.

How to see for which values a matrix loses rank?

I'm using Matlab and I have the following matrix:
where c2 mens cos(q2), c23 means cos(q2+q3), c234 means cos(q2+q3+q4) and analogously: s2 means sin(q2), s23 means sin(q2+q3), s234 means sin(q2+q3+q4)
Is there a way to see for which values of q2, q3 and q4 the matrix loses rank?

assign standard tolerance to isequal funtion Matlab

I am Using matlab 2012b, I came through a some simple problem when using the function isequal. I have to round the floating values. but, I got some basic errors because of some exceptions.
In my file the values are rounded to nearest integer in most cases. but, they are some exceptions like
if i have a variable value
a = X.4675
it has been rounded to X in many cases but there few cases it has been rounded to X+1.
my task is just to compare and check the equality. In this case it should be true in both X and X+1 cases. hence, I need to modify isequal function with a tolerance of 1.
isequal({b1, b2, b3, b4},{B1, B2, B3, B4})
b1, b2... are values after rounding the original, B1, B2 ....are standard values to camapare. now I want to give a tolerance of 1
B1 = round(b1)|| B1 = round(b1)+1
Note: B1,B2.... values are standard, I need to compare all at a once.

A set of results in Decision Tree

I have a data which is 1672x6. I have put some of them in the picture.
where x values are A1 A2 A3 A4 A5 A6 and y values are B1 B2 ....B1672.
I used the following code while generating decision trees:
vars = {'A1', ' A2 ','A3',' A4 ','A5',' A6'}
x = [A1 A2 A3 A4 A5 A6];
y = [B];
t = classregtree(x, y, 'method','classification', 'names',vars, ...
'categorical',[2 4], 'prune','off');
view(t)
and it generates super crazy trees like
I want to get the values which are greater than the values that I gave. When I say :
inst = [3 2.3 2 0 1 0];
prediction = eval(t, inst)
It only gives me the B value (like B271) which has that variable but I want to get all B variables which have greater values than inst variable such as A1>3 A2>2.3 A3>2 A4>0 A5>1 A6>0. How can I get them?
You seem to confuse two things: decision tree and finding desired rows
If you want to find all the rows that are greater than inst, the following is a simple code that prints all such rows.
for i = 1:size(B,1)
if all(a(i,:)>inst)==1
i,
end
end
However, decision tree is a totally different topic. In a decision tree, you have a set of conditions (A1 to A6 in your case) and many rows for training (B1 to B1672) and a consequence for each one of them. When a new test case is queried, the machine decides on best possible consequence out of all the consequences.
Some decision tree totorials: 1, 2 and wikipedia

Match cell arrays with different size based on two conditions in Matlab

RECCELL is a cell array with 8 columns and 30000 rows:
C1 C2 C3 C4 C5 C6 C7 C8
'AA' 1997 19970102 1 'BACHE' 'MORI' 148 127
'AA' 1997 19970108 2 'MORGAN' [] 1595 0
'AA' 1997 19970224 3 'KEMSEC' 'FATHI' 1315 297
CONCELL is a cell array with 4 columns and 70000 rows:
C1 C2 D3 D4
'AA' 1997 19970116 2,75
'AA' 1997 19970220 2,71
'AA' 1997 19970320 2,61
I would like to add to RECCELL the 4 columns of CONCELL only in case the C1s match and C3 and D3 (both dates) are the closest possible. For instance I would get in this example:
C1 C2 C3 C4 C5 C6 C7 C8 C1 C2 D3 D4
'AA' 1997 19970102 1 'BACHE' 'MORI' 148 127 'AA' 1997 19970116 2,75
'AA' 1997 19970108 2 'MORGAN' [] 1595 0 'AA' 1997 19970116 2,75
'AA' 1997 19970113 3 'KEMSEC' 'FATHI' 1315 297 'AA' 1997 19970220 2,71
To the first row of RECCELL corresponds the first row of CONCELL.
To the second row of RECCELL corresponds the first row of CONCELL.
To the third row of RECCELL corresponds the second row of CONCELL.
The code I have so far is:
[~, indCon, indREC] = intersect(CONCELL(:,1), RECCELL(:,1));
REC_CON=[RECCELL(indREC,:),CONCELL(indCon,:)];
NO_REC_CON= RECCELL(setdiff(1:size(RECCELL,1), indREC),:);
It's wrong because I cannot use intersect for a string element and because I am not considering the second condition, which is to choose the closest dates.
Can someone help me? Thank you
I would suggest to do this inside a for loop as the cells are very tall.
(Note: it seems like the date format (C3/D3) in the cell is a double opposed to a string, thus needs to be converted first for using datenum)
n=size(RECCELL,1);
ind=zeros(n,1);
rd=datenum(num2str(cell2mat(CONCELL(:,3))),'yyyymmdd'); % convert double to string
for k=1:n
a=find(ismember(CONCELL(:,1),RECCELL(k,1))==1); % find indices of matching C1s
if ~isempty(a) % do only if there is a match for the C1s
dnk=datenum(num2str(RECCELL{k,3}),'yyyymmdd'); % convert double to string
[~,f]=min((rd(a)-dnk).^2); % find closest date of the subset a
ind(k,1)=a(f); % assign index of closest match to ind
RECCELL(k,(end+1):(end+4))=CONCELL(ind(k,1),:); % add CONCELL to RECCELL, be aware that other rows will now display empty cells, and a row of RECCELL can keep 'growing'
end
end
The vector ind contains the indices of the closest match in CONCELL for each entry in RECCELL. When it contains a 0, no match was found between the C1s.
Edit: One possible solution to avoid increasing the number of columns of RECCELL if multiple CONCELL entries are added to the same RECCELL entry is the following which results in a adding a single column to the RECCELL matrix:
n=size(RECCELL,1);
RECCELL{1,end+1}=[]; % to add a single empty column to RECCELL
ind=zeros(n,1);
rd=datenum(num2str(cell2mat(CONCELL(:,3))),'yyyymmdd'); % convert double to string
for k=1:n
a=find(ismember(CONCELL(:,1),RECCELL(k,1))==1); % find indices of matching C1s
if ~isempty(a) % do only if there is a match for the C1s
dnk=datenum(num2str(RECCELL{k,3}),'yyyymmdd'); % convert double to string
[~,f]=min((rd(a)-dnk).^2); % find closest date of the subset a
ind(k,1)=a(f); % assign index of closest match to ind
if isempty(RECCELL{k,end}) % if nothing is in this cell, add the CONCELL entry to it
RECCELL{k,end}=CONCELL(ind(k,1),:);
else % if something is already in, add the new CONCELL entry to the cell
RECCELL{k,end}(end+1,1:4)=CONCELL(ind(k,1),:);
end
end
end