I have following data:
kx = 20;
ky = 20;
k = [kx ky];
PointsL = [
[ 32 0 0] % P1
[387 0 0]
[475 0 0]
[475 30 0]
[602 30 0] % P5
[602 220 0]
[475 220 0]
[475 737 0]
[387 737 0]
[ 32 737 0] % P10
[ 32 555 0]
[ 0 555 0]
[ 0 277 0]
[ 27 277 0]
[ 27 250 0] % P15
[ 0 250 0]
[ 0 57 0]
[ 32 57 0] % P18
];
PointsH = [
[ 32 0 270] % P1
[387 0 270]
[475 0 183]
[475 30 183]
[602 30 183] % P5
[602 220 183]
[475 220 183]
[475 737 183]
[387 737 270]
[ 32 737 270] % P10
[ 32 555 270]
[ 0 555 270]
[ 0 277 270]
[ 27 277 270]
[ 27 250 270] % P15
[ 0 250 270]
[ 0 57 270]
[ 32 57 270] % P18
];
PointsL are points of the lower surface - all with z=0.
PointsH are points of the higher surface - changable in z-axis.
All of them are representing points of room.
Following code draws 3d model:
plength = size(PointsL,1);
for i=1:plength
if i == 1
pl1 = PointsL(plength,:);
ph1 = PointsH(plength,:);
else
pl1 = PointsL(i-1,:);
ph1 = PointsH(i-1,:);
end
pl2 = PointsL(i,:);
ph2 = PointsH(i,:);
line([pl1(1) pl2(1)], [pl1(2) pl2(2)], [pl1(3) pl2(3)]);
line([ph1(1) ph2(1)], [ph1(2) ph2(2)], [ph1(3) ph2(3)]);
line([pl1(1) ph1(1)], [pl1(2) ph1(2)], [pl1(3) ph1(3)]);
end
p1 = PointsH(2,:);
p2 = PointsH(9,:);
line([p1(1) p2(1)], [p1(2) p2(2)], [p1(3) p2(3)]);
p1 = PointsH(4,:);
p2 = PointsH(7,:);
line([p1(1) p2(1)], [p1(2) p2(2)], [p1(3) p2(3)]);
Is it possible to get height (z value) for given x,y values ?
Ok, I was going to say that this could easily be done using TriScatteredInterp() on PointsH. I realised that it was not that simple to get it to produce what I wanted. I resorted to adding extra points and moving them around to create the right interpolation triangles.
I finally got something that can produce the z-value corresponding to the point (a,b).
Here is what I ended up doing...
epsilon = 1e-8;
PointsL_diff = epsilon*[
[ -1 0 0] % P1
[ 0 -1 0]
[ 0 -1 0]
[ 1 0 0]
[ 0 -1 0] % added
[ 1 -1 0]
[ 1 0 0] % P5
[ 0 -1 0]
[ 1 1 0]
[ 1 1 0]
[ 0 1 0]
[ 1 0 0] % added
[ 0 1 0]
[ -1 0 0] % P10
[ 0 1 0] % added
[ -1 1 0]
[ -1 1 0]
[ -1 0 0]
[ 0 -1 0] % added
[ -1 -1 0]
[ -1 1 0] % P15
[ -1 0 0]
[ 0 1 0] % added
[ -1 -1 0]
[ -1 -1 0] % P18
];
PointsL = [
[ 32 0 0] % P1
[ 32 0 0] % added
[387 0 0]
[475 0 0]
[475 0 0] % added
[475 30 0]
[602 30 0] % P5
[602 30 0] % added
[602 220 0]
[475 220 0]
[475 737 0]
[475 737 0] % added
[387 737 0]
[ 32 737 0] % P10
[ 32 737 0] % added
[ 32 555 0]
[ 0 555 0]
[ 0 277 0]
[ 0 277 0] % added
[ 27 277 0]
[ 27 250 0] % P15
[ 0 250 0]
[ 0 250 0] % added
[ 0 57 0]
[ 32 57 0] % P18
];
PointsH = [
[ 32 0 270] % P1
[387 0 270]
[475 0 183]
[475 30 183]
[602 30 183] % P5
[602 220 183]
[475 220 183]
[475+epsilon 220 183] % added
[475 220+epsilon 183] % added
[475 737 183]
[387 737 270]
[387 220 270] % added
[ 32 737 270] % P10
[ 32 555 270]
[ 0 555 270]
[ 0 277 270]
[ 27 277 270]
[ 27 250 270] % P15
[ 0 250 270]
[ 0 57 270]
[ 32 57 270] % P18
];
% plot bounds
x_min = -200;
x_max = 800;
y_min = -200;
y_max = 800;
newPointsL = PointsL + PointsL_diff;
x = [PointsH(:,1); newPointsL(:,1); x_min; x_max; x_min; x_max];
y = [PointsH(:,2); newPointsL(:,2); y_min; y_min; y_max; y_max];
z = [PointsH(:,3); newPointsL(:,3); 0; 0; 0; 0];
F = TriScatteredInterp(x,y,z); % default is linear interpolation
% find z-value for point (a,b)
a = 100;
b = 200;
z_value = F(a,b)
% generate mesh and plot surface
ti_x = x_min:10:x_max;
ti_y = y_min:10:y_max;
[qx,qy] = meshgrid(ti_x,ti_y);
qz = F(qx,qy);
mesh(qx,qy,qz);
hold on;
plot3(x,y,z,'o');
... and here is the figure the code produces:
Quick general way:
Try Data Cursor option in the figure windows Tool bar.
And, if you want to do it programatically, follow this link.
Related
I'd like to get a trace of function calls inside comctl32.dll beginning when the left mouse button is pressed on a tree control item and while the mouse button is held down.
I can set a breakpoint on comctl32!TV_ButtonDown and then use wt when the breakpoint is hit but this requires me to release the mouse button and interact with WinDbg. When I try to use a command string for my breakpoint like this: bp comctl32!TV_ButtonDown "wt -m comctl32", the tracing stops immediately after starting upon hitting the breakpoint:
Tracing COMCTL32!TV_ButtonDown to return address 00007ffd`57a48f1d
0 instructions were executed in 0 events (0 from other threads)
Function Name Invocations MinInst MaxInst AvgInst
0 system calls were executed
COMCTL32!TV_ButtonDown+0x5:
00007ffd`57b03bd9 48896c2418 mov qword ptr [rsp+18h],rbp ss:000000b7`746f8b00=0000000000000201
Is what I am attempting possible? Are there any alternatives?
not 64 bit but 32 bit
supply the end address
( top of stack or return address is what i give #$ra and don't release the mouse
it is not mandatory that you give #$ra but you should be sure that you will reach the end address
eventually without releasing the mouse lsft button)
0:000> bl
0 e Disable Clear 6e57a2ee 0001 (0001) 0:**** COMCTL32!TV_ButtonDown "wt -m comctl32 #$ra"
0:000> g
17 0 [ 0] COMCTL32!TV_ButtonDown
10 0 [ 1] COMCTL32!GetMessagePosClient
3 0 [ 2] USER32!GetMessagePos
18 3 [ 1] COMCTL32!GetMessagePosClient
17 0 [ 2] USER32!ScreenToClient
25 20 [ 1] COMCTL32!GetMessagePosClient
20 45 [ 0] COMCTL32!TV_ButtonDown
22 0 [ 1] COMCTL32!TV_DismissEdit
14 0 [ 2] USER32!IsWindowVisible
26 14 [ 1] COMCTL32!TV_DismissEdit
10 0 [ 2] USER32!GetDlgCtrlID
33 24 [ 1] COMCTL32!TV_DismissEdit
10 0 [ 2] USER32!SetWindowLongW
48 34 [ 1] COMCTL32!TV_DismissEdit
16 0 [ 2] COMCTL32!TV_InvalidateItem
40 0 [ 3] COMCTL32!TV_GetItemRect
24 40 [ 2] COMCTL32!TV_InvalidateItem
4 0 [ 3] USER32!NtUserRedrawWindow
27 44 [ 2] COMCTL32!TV_InvalidateItem
52 105 [ 1] COMCTL32!TV_DismissEdit
4 0 [ 2] USER32!NtUserShowWindow
58 109 [ 1] COMCTL32!TV_DismissEdit
34 0 [ 2] COMCTL32!CCSendNotify
25 0 [ 3] USER32!GetParent
40 25 [ 2] COMCTL32!CCSendNotify
18 0 [ 3] USER32!GetWindow
44 43 [ 2] COMCTL32!CCSendNotify
10 0 [ 3] USER32!GetDlgCtrlID
57 53 [ 2] COMCTL32!CCSendNotify
24 0 [ 3] USER32!GetWindowThreadProcessId
60 77 [ 2] COMCTL32!CCSendNotify
1 0 [ 3] kernel32!GetCurrentProcessIdStub
1 0 [ 3] kernel32!GetCurrentProcessId
3 0 [ 3] KERNELBASE!GetCurrentProcessId
87 82 [ 2] COMCTL32!CCSendNotify
24 0 [ 3] USER32!SendMessageW
109 106 [ 2] COMCTL32!CCSendNotify
16 0 [ 3] COMCTL32!InOutAtoW
118 122 [ 2] COMCTL32!CCSendNotify
3 0 [ 3] COMCTL32!__security_check_cookie
120 125 [ 2] COMCTL32!CCSendNotify
67 354 [ 1] COMCTL32!TV_DismissEdit
4 0 [ 2] USER32!NtUserDestroyWindow
75 358 [ 1] COMCTL32!TV_DismissEdit
3 0 [ 2] COMCTL32!__security_check_cookie
77 361 [ 1] COMCTL32!TV_DismissEdit
27 483 [ 0] COMCTL32!TV_ButtonDown
3 0 [ 1] COMCTL32!__security_check_cookie
29 486 [ 0] COMCTL32!TV_ButtonDown
515 instructions were executed in 514 events (0 from other threads)
Function Name Invocations MinInst MaxInst AvgInst
COMCTL32!CCSendNotify 1 120 120 120
COMCTL32!GetMessagePosClient 1 25 25 25
COMCTL32!InOutAtoW 1 16 16 16
COMCTL32!TV_ButtonDown 1 29 29 29
COMCTL32!TV_DismissEdit 1 77 77 77
COMCTL32!TV_GetItemRect 1 40 40 40
COMCTL32!TV_InvalidateItem 1 27 27 27
COMCTL32!__security_check_cookie 3 3 3 3
KERNELBASE!GetCurrentProcessId 1 3 3 3
USER32!GetDlgCtrlID 2 10 10 10
USER32!GetMessagePos 1 3 3 3
USER32!GetParent 1 25 25 25
USER32!GetWindow 1 18 18 18
USER32!GetWindowThreadProcessId 1 24 24 24
USER32!IsWindowVisible 1 14 14 14
USER32!NtUserDestroyWindow 1 4 4 4
USER32!NtUserRedrawWindow 1 4 4 4
USER32!NtUserShowWindow 1 4 4 4
USER32!ScreenToClient 1 17 17 17
USER32!SendMessageW 1 24 24 24
USER32!SetWindowLongW 1 10 10 10
kernel32!GetCurrentProcessId 1 1 1 1
kernel32!GetCurrentProcessIdStub 1 1 1 1
0 system calls were executed
eax=00000000 ebx=00000201 ecx=422f0fd7 edx=77a370f4 esi=002d9590 edi=00000200
eip=6e542888 esp=0012fcc4 ebp=0012fd00 iopl=0 nv up ei pl zr na pe nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246
COMCTL32!TV_WndProc+0x577:
6e542888 e90a060000 jmp COMCTL32!TV_WndProc+0x5de (6e542e97)
As Steve Eddin posted in http://blogs.mathworks.com/steve/2011/03/08/tips-for-reading-a-camera-raw-file-into-matlab/, I followed and copied the following code, running in MATLAB 2014b. As a result, I got the following error."Reading images with a BitsPerSample of 10 is not supported". I checked info and info.SubIFDs{1}, I got the following results in INFOS. I have searched on google for the problem, but there is no enough information. Therefore, I posted this problem here and hope someone gives me solutions.
CODE::
warning off MATLAB:tifflib:TIFFReadDirectory:libraryWarning
t = Tiff('Non-Invasive DNGs/WP_20150311_15_03_14_Raw__highres.dng','r');
offsets = getTag(t,'SubIFD');
setSubDirectory(t,offsets(1));
cfa = read(t);
close(t);
ERROR::
Error using Tiff.constructBlankOutputImage (line 2448)
Reading images with a BitsPerSample of 10 is not supported.
Error in Tiff/readAllStrips (line 2046)
imageData = obj.constructBlankOutputImage(imageSize,bps,sampleFormat);
Error in Tiff/read (line 1507)
[varargout{:}] = obj.readAllStrips();
Error in readDNG (line 11)
cfa = read(t);
INFOS_1::
FileSize: 43676288
Format: 'tif'
FormatVersion: []
Width: 960
Height: 544
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 1
BitsPerSample: [8 8 8]
Compression: 'Uncompressed'
PhotometricInterpretation: 'RGB'
StripOffsets: 69248
SamplesPerPixel: 3
RowsPerStrip: 544
StripByteCounts: 1566720
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: [255 255 255]
MinSampleValue: [0 0 0]
Thresholding: 1
Offset: 8
Make: 'Nokia'
Model: 'Lumia 1020'
Software: 'Nokia RAW-to-DNG converter v01.00.06'
DateTime: '2015:03:11 15:03:11'
SubIFDs: {[1x1 struct]}
DigitalCamera: [1x1 struct]
DNGVersion: [1 3 0 0]
DNGBackwardVersion: [1 3 0 0]
UniqueCameraModel: 'Nokia Lumia 1020'
ColorMatrix1: [1.6183 -0.7414 0.1000 -0.2665 1.1286 0.3664 0.1114 0.0951 0.8522]
ColorMatrix2: [0.9390 -0.1511 -0.0964 -0.3983 1.2153 0.1384 -0.0880 0.4120 0.5662]
CameraCalibration1: [1.0361 0 0 0 1 0 0 0 0.9688]
CameraCalibration2: [0.9851 0 0 0 0.9926 0 0 0 0.9763]
AnalogBalance: [1 1 1]
AsShotNeutral: [0.8476 1 0.6481]
BaselineExposure: -1
BaselineNoise: 1
BaselineSharpness: 1
LinearResponseUnit: 0.9999
ShadowScale: 1
DNGPrivateData: [1x1246 double]
MakerNoteSafety: 1
CalibrationIlluminant1: 17
CalibrationIlluminant2: 21
AliasLayerMetadata: [58 48 51 58 49 49 32 49 53 58 48 51 58 49 49 0]
UnknownTags: [7x1 struct]
INFOS_2::SubIFDs{1}
FileSize: 43676288
Format: 'tif'
FormatVersion: []
Width: 7728
Height: 4352
BitDepth: 10
ColorType: 'CFA'
FormatSignature: [73 73 42 0]
ByteOrder: 'little-endian'
NewSubFileType: 0
BitsPerSample: 10
Compression: 'Uncompressed'
PhotometricInterpretation: 'CFA'
StripOffsets: 1635968
SamplesPerPixel: 1
RowsPerStrip: 4352
StripByteCounts: 42040320
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 1023
MinSampleValue: 0
Thresholding: 1
Offset: 56578
CFAPlaneColor: [0 1 2]
CFALayout: 1
BlackLevelRepeatDim: [2 2]
BlackLevel: [0 0 0 0]
WhiteLevel: 1023
DefaultScale: [1 1]
DefaultCropOrigin: [0 0]
DefaultCropSize: [7728 4352]
BayerGreenSplit: 1
AntiAliasStrength: 1
BestQualityScale: 1
UnknownTags: [4x1 struct]
I have matrix X , mX2, I want to result a matrix S of size
size(unique(X(:,2),1) X size(unique(X(:,2),1)
for each S(i,j) I want to count how many times i,j appeared together.
for example:
X = [1 11 ;
2 11;
3 11;
5 23;
6 23;
1 23;
9 24;
9 25;
3 23;
10 23]
unique(X(:,2))
11
23
24
25
S should be:
0 2 0 0
0 0 0 0
0 0 0 1
0 0 0 0
(I don't care about diagonals, and it could either have them or not, also,S could be symmetric).
S(1,2) = 2
because 11 and 23 (which are in position 1,2) appeared together twice (i.e with the same value in X(:,1)).
Thanks
This is one way of doing it:
[~, ~, n1] = unique(X(:,1));
[~, ~, n2] = unique(X(:,2));
B = accumarray([n2 n1],1);
S = B*B';
This gives the full matrix:
>> S
S =
3 2 0 0
2 5 0 0
0 0 1 1
0 0 1 1
To remove the diagonal and lower triangle you can use
S = triu(B*B',1);
which yields
>> S
S =
0 2 0 0
0 0 0 0
0 0 0 1
0 0 0 0
Try the following:
% convert each columns to indices starting from 1
[a,~,aa] = unique(X(:,1));
[b,~,bb] = unique(X(:,2));
% group occurences of col2 according to values of col1
C = accumarray(aa, bb, [], #(x){x});
% keep only occurences of two or more values
C = C(cellfun(#numel,C) > 1);
% in case of three or more values co-occured, generate all pairs
C = cellfun(#(v) nchoosek(v,2), C, 'UniformOutput',false);
% concatenate all pairs
C = cell2mat(C);
% build count matrix
C = sparse(C(:,[1 2]), C(:,[2 1]), 1);
C = full(C);
The result in this case (obviously a symmetric matrix):
>> C
C =
0 2 0 0
2 0 0 0
0 0 0 1
0 0 1 0
or pretty-printed with row/column headers:
>> [{[]} num2cell(b'); num2cell(b) num2cell(C)]
ans =
[] [11] [23] [24] [25]
[11] [ 0] [ 2] [ 0] [ 0]
[23] [ 2] [ 0] [ 0] [ 0]
[24] [ 0] [ 0] [ 0] [ 1]
[25] [ 0] [ 0] [ 1] [ 0]
syms t theta chy sy real;
A = [0 0 0 0; 0 -theta -0.5 0;0 -0.5 0 0;0 0 0 0];
B = [0 theta/2 0.5 0; theta/2 0 0 0;0.5 0 0 0;0 0 0 0];
C = [0 (1-(theta^2))/2 -(theta/2) 0;(1-(theta^2))/2 0 0 0; -(theta/2) 0 0 0;0 0 0 0];
D = sym(zeros(4,4));
CS = cat(3,A,B,C,D);
Now when I type
>> CS(:,1,3)
ans =
[ 0, 1/2 - theta^2/2, -theta/2, 0]
[ 1/2 - theta^2/2, 0, 0, 0]
[ -theta/2, 0, 0, 0]
[ 0, 0, 0, 0]
>> CS(:,:,3)
ans =
[ 0, 1/2 - theta^2/2, -theta/2, 0]
[ 1/2 - theta^2/2, 0, 0, 0]
[ -theta/2, 0, 0, 0]
[ 0, 0, 0, 0]
which is supposed to be different from CS(1,1,3) and CS(:,1,3).
>> CS(1,1,3)
ans =
[ 0, 1/2 - theta^2/2, -theta/2, 0]
[ 1/2 - theta^2/2, 0, 0, 0]
[ -theta/2, 0, 0, 0]
[ 0, 0, 0, 0]
All give the same values. How do I access the first value in that particular matrix. I don't want to use the A/B/C matrices.
It is working fine for me (R2011a):
syms t theta chy sy real;
A = [0 0 0 0; 0 -theta -0.5 0;0 -0.5 0 0;0 0 0 0];
B = [0 theta/2 0.5 0; theta/2 0 0 0;0.5 0 0 0;0 0 0 0];
C = [0 (1-(theta^2))/2 -(theta/2) 0;(1-(theta^2))/2 0 0 0; -(theta/2) 0 0 0;0 0 0 0];
D = sym(zeros(4,4));
CS = cat(3,A,B,C,D);
>> CS(:,1,3)
ans =
0
1/2 - theta^2/2
-theta/2
0
>> CS(:,:,3)
ans =
[ 0, 1/2 - theta^2/2, -theta/2, 0]
[ 1/2 - theta^2/2, 0, 0, 0]
[ -theta/2, 0, 0, 0]
[ 0, 0, 0, 0]
>> CS(1,1,3)
ans =
0
EDIT: As you see, R2011a gives the expected results. However, I've just checked it on R2010a (the OP's version) and also got your results... so you probably need an upgrade :)
I have a matrix (Data) which looks like this:
(start) (stop) (strand) (gene number)
[ 1 29 1 1]
[ 32 38 1 1]
[ 44 60 1 1]
[ 66 70 0 2]
[ 75 80 0 2]
[ 81 88 0 3]
[ 99 102 0 3]
[ 111 160 0 3]
[ 166 170 1 4]
[ 171 188 1 4]
which I have plotted onto a graph using the first two columns as X positions, and a set Y position. This is the code I have up till now:
if nargin<4, strands = 0; end;
if nargin<3, height = 0.1; end;
if nargin<2, y = 2.1; end;
for k=1:size(cds,1),
xc = [cds(k,1) cds(k,2) cds(k,2) cds(k,1)];
if strands,
if cds(k,3), % minus strand
yc = [y y y-height/2 y-height/2];
c = 'r';
else % plus strand
yc = [y+height/2 y+height/2 y y];
c = 'b';
end
else
yc = [y+height/2 y+height/2 y-height/2 y-height/2];
c = 'b';
end
h(k) = patch(xc,yc,c);
end
What I'm trying to do is add lines underneath each 'box' which corresponds to the gene number (4th collumn of the data matrix). How would I go about doing this with the plot function?
It's not clear from your question how you want the lines to indicate the gene numbers, I assume you want different colors for each type. Here is how I would do it:
cds = [
1 29 1 1
32 38 1 1
44 60 1 1
66 70 0 2
75 80 0 2
81 88 0 3
99 102 0 3
111 160 0 3
166 170 1 4
171 188 1 4
];
strands = 0;
height = 0.1;
y = 2.1;
[g,gIdx,gNum] = unique(cds(:,4));
clr = 'gcmykrb';
for k=1:size(cds,1),
xc = [cds(k,1) cds(k,2) cds(k,2) cds(k,1)];
if strands,
if cds(k,3), % minus strand
yc = [y y y-height/2 y-height/2];
c = 'r';
else % plus strand
yc = [y+height/2 y+height/2 y y];
c = 'b';
end
else
yc = [y+height/2 y+height/2 y-height/2 y-height/2];
c = 'b';
end
h(k) = patch(xc,yc,c);
hLine(k) = line([cds(k,1) cds(k,2)], [y-3*height/4 y-3*height/4], ...
'LineWidth',5, 'Color',clr(gNum(k)));
end
legend(hLine(gIdx), num2str(g), 'Orientation','horizontal')