Microsoft.Office.Interop.PowerPoint Chart - with broken y-Axis - winforms

We are using the Interop PowerPoint Chart type to generate an area chart as shown in the figure. We need the "broken" y-Axis. We dont want the break on the bars itself - we need the break only on the y-Axis. But are unable to find a property or a method to achieve this.
This a winforms application. Would really appreciate some pointers...

Accidentally stumbled upon this question, and I let my curiosity takes over.
I got how it's done taken from this site.
I'm using example data from above site for this walkthrough.
The step roughly like this:
Assign cut value for data separation. Separate data using a cut value (I use cut value 7,500,000 for the example)
This is data separation from the example (above is the original, below is the separated):
May June July
London 1,234,565 1,452,369 1,478,852
Paris 2,363,645 34,568,876 5,562,413
Madrid 32,645,254 3,211,654 5,857,421
Brussels 5,914,753 5,544,221 3,620,015
Lisbon 5,824,676 4,541,258 4,015,876
Munich 2,501,478 6,325,698 4,569,872
May June July Column4 Column5 Column6
London 1,234,565 1,452,369 1,478,852 0 0 0
Paris 2,363,645 7,500,000 5,562,413 0 34,568,876 0
Madrid 7,500,000 3,211,654 5,857,421 32,645,254 0 0
Brussels 5,914,753 5,544,221 3,620,015 0 0 0
Lisbon 5,824,676 4,541,258 4,015,876 0 0 0
Munich 2,501,478 6,325,698 4,569,872 0 0 0
Assign Column4, Column5, and Column6 into secondary axis.
Dim c As Microsoft.Office.Interop.PowerPoint.Chart
Dim sc As Microsoft.Office.Interop.PowerPoint.SeriesCollection = Nothing
Dim sr As Microsoft.Office.Interop.PowerPoint.Series = Nothing
sc = c.SeriesCollection
For i = 4 To sc.Count
sr = sc.SeriesCollection(i)
sr.AxisGroup = Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlSecondary
Next
Change Primary and Secondary Axis scale to fit as though the chart was separated. I change the primary axis scale from 0 to 1.6e7, and secondary axis scale from -7.0e7 to 7.0e7. At the same time, change display unit in millions, and remove all gridlines.
Dim ax As Microsoft.Office.Interop.PowerPoint.Axes
Dim axpri As Microsoft.Office.Interop.PowerPoint.Axis
Dim axsec As Microsoft.Office.Interop.PowerPoint.Axis
ax = c.Axes
axpri = ax.Item(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, _
Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlPrimary)
axsec = ax.Item(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, _
Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlSecondary)
axpri.MinimumScale = 0
axpri.MaximumScale = 1.6e7
axpri.DisplayUnit = Microsoft.Office.Interop.PowerPoint.XlDisplayUnit.xlMillions
axpri.HasMajorGridlines = False
axpri.HasMinorGridlines = False
axsec.MinimumScale = -7.0e7
axsec.MaximumScale = 7.0e7
axsec.DisplayUnit = Microsoft.Office.Interop.PowerPoint.XlDisplayUnit.xlMillions
axsec.HasMajorGridlines = False
axsec.HasMinorGridlines = False
Change Primary and Secondary Axis number format so that each axis only show its own intended value. Primary Axis more than 8M will not be shown, and Secondary Axis less than 30M will not be shown.
axpri.TickLabels.NumberFormat = "[<=8]0;;;"
axsec.TickLabels.NumberFormat = "[>=30]0;;;"
Recolor series in Secondary Axis to match series in Primary Axis.
Dim srPrev As Microsoft.Office.Interop.PowerPoint.Series = Nothing
For i = 4 To sc.Count
sr = sc.SeriesCollection(i)
srPrev = sc.SeriesCollection(i - 3)
sr.Format.Fill.ForeColor.RGB = srPrev.Format.Fill.ForeColor.RGB
Next
Delete Legend for Column4, Column5, and Column6 for a seamless Chart Legend.
c.Legend.LegendEntries(4).Delete()
c.Legend.LegendEntries(5).Delete()
c.Legend.LegendEntries(6).Delete()
[Optional] Add a neat color gradient for Data Points that exceed cut values.
Dim p As Microsoft.Office.Interop.PowerPoint.Point = Nothing
p = c.SeriesCollection("June").Points("Paris")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 270
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.8)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.97)
p = c.SeriesCollection("May").Points("Madrid")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 270
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.8)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.97)
p = c.SeriesCollection("Column5").Points("Paris")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 90
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.7)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.95)
p = c.SeriesCollection("Column4").Points("Madrid")
p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
p.Format.Fill.GradientAngle = 90
p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.7)
p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.95)
Voila! Hard work pays off, a broken y axis in PowerPoint chart.

Related

how to create multi line chart with single datatable in vb.net

I am working on vb.net application where i have to create a multi line chart. The table coming from the database using storing procedure is:-
TagName On Off Trip
P1 0 0 1
P2 0 1 1
P3 0 1 0
Q1 0 1 0
Q2 1 0 1
Q3 2 2 2
W1 4 2 1
W2 2 0 1
W3 1 1 0
W4 0 1 1
W5 2 1 1
And the code in vb.net i used to bind the chart named "chTrend" is:-
ds = ObjTags.GetTrendData()
If (ds.Tables(0).Rows.Count > 0) Then
dt = ds.Tables(0)
chTrend.DataSource = dt
chTrend.Series(0).XValueMember = "TagName"
chTrend.Series(0).YValueMembers = "On"
chTrend.Series(1).XValueMember = "TagName"
chTrend.Series(1).YValueMembers = "Off"
chTrend.Series(1).XValueMember = "TagName"
chTrend.Series(1).YValueMembers = "Trip"
For i = 0 To 2
chTrend.Series(i).ChartType = SeriesChartType.Line
chTrend.Series(i).IsVisibleInLegend = True
chTrend.Series(i).IsValueShownAsLabel = True
chTrend.Series(i).ToolTip = "Data Point Y Value #VALY{G}"
chTrend.Series(i).BorderWidth = 3
Next
End If
When i run the program a Error is coming as following
"Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index"
At the position
chTrend.Series(0).XValueMember = "TagName"
how to solve this?
Assuming that your DataTable only has the four DataColumns {TagName, On. Off. Trip}, then replace everything in your shown code below the line:
chTrend.DataSource = dt
with this.
chTrend.Series.Clear() ' clears any existing series
Dim s As Series
For columnIndex As Int32 = 1 To dt.Columns.Count - 1
Dim name As String = dt.Columns(columnIndex).ColumnName
s = chTrend.Series.Add(name)
s.XValueMember = dt.Columns(0).ColumnName
s.YValueMembers = name
s.ChartType = SeriesChartType.Line
s.IsVisibleInLegend = True
s.IsValueShownAsLabel = True
s.ToolTip = "Data Point Y Value #VALY{G}"
s.BorderWidth = 3
Next
chTrend.DataBind() ' loads the data from dt to the chart
The Chart databinding is a not a binding in the normal sense of binding. You need to tell the chart to copy the data from the source so that it has something to plot. That is what the DataBind method does.

VBA - Chart series number of values limitation

I am trying to plot an array which is in the order of 10.000 or more values, but the chart is only plotting almost a 10th of those numbers.
The arrays engSpdPoints and indTrqPoints have more than 10.000 values but when I check the data on the graph it only shows me less than 2.000 data points.
Set residencySrs = .SeriesCollection.NewSeries
With residencySrs
.XValues = engSpdPoints
.Values = indTrqPoints
.MarkerStyle = xlMarkerStyleCircle
.Format.Line.Visible = msoFalse
.Name = residency(1)(4)
End With
With .Axes(xlCategory)
.HasTitle = True
.AxisTitle.Caption = "Eng Speed (rpm)"
.TickLabels.NumberFormat = "0"
End With
With .Axes(xlValue)
.HasTitle = True
.AxisTitle.Caption = "Torque (Nm)"
.TickLabels.NumberFormat = "0"
End With
End With
It would be great not to have the data stored in a range of cells in another sheet.

MATLAB data indexing issue. What is going on here?

Let I be the identity, D an orthonormal projection, and p a vector.
I realized that several of my lines of code combined to be (I-(I-D))(p) and I could just simplify it to D(p). In replacing it, I computed the new method along-side the old to double check I was computing the same thing (Earlier in my code I had a line that was D = I - D. The D you see here is that D.) I wasn't getting the same answer, and traced it to an error in indexing D.
Here you can see I'm using the debugger and checking portions of D and getting the wrong data returned.
The values in the data explorer on the right are what I'd expect them to be. Sometimes I get what I'd expect from D(:,:,k,1), and sometimes I don't, even when I make the queries right after each other.
The vectors those red arrows are pointing to should be the same. Nothing else changed or was computed between those lines, and k = 2 when the first line was run. I've closed MATLAB and restarted it and get the same issue every time. (D depends on random input, but I'm not altering the seed, so I get the same thing every first run after newly opening MATLAB. The way D is computed, I do expect D(:,:,1,1) to be the identity matrix.)
What in the world is going on? Any help is appreciated.
I have wondered if MATLAB is messing with me on purpose. Sometimes when I open it, a pop-up dialog box says I need to update my student license. I click the update button, but nothing ever happens and the dialog box never closes, so I click cancel.
Edit:
K>> whos D P
Name Size Bytes Class Attributes
D 4-D 4608 double
P 4x1x6 192 double
K>> size(D)
ans =
4 4 6 6
I've been playing around with A and B a bit, and I get the same thing. Sometimes it computes correctly and sometimes it doesn't.
K>> B=permute(P,[1,3,2])
B =
0.4155 0.27554 0.52338 0.6991 -0.11346 0.20999
0.53573 -0.83781 0.53182 -0.022364 0.60291 -0.62601
-0.49246 -0.46111 -0.39168 0.45919 0.42377 0.47074
0.54574 0.097595 0.53835 -0.54763 0.66637 0.58516
K>> A=D
A(:,:,1,1) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
A(:,:,2,1) =
0.99071 -0.091198 0.0020814 -0.029755
-0.091198 0.10503 0.020426 -0.292
0.0020814 0.020426 0.99953 0.0066643
-0.029755 -0.292 0.0066643 0.90473
A(:,:,3,1) =
0.46769 0.019281 -0.49725 0.036486
0.019281 0.9993 0.018011 -0.0013215
-0.49725 0.018011 0.53551 0.034083
0.036486 -0.0013215 0.034083 0.9975
A(:,:,4,1) =
0.96774 0.063488 -0.10826 0.12438
0.063488 0.87506 0.21304 -0.24477
-0.10826 0.21304 0.63673 0.41737
0.12438 -0.24477 0.41737 0.52047
A(:,:,5,1) =
0.7542 0.031217 0.42575 0.056052
0.031217 0.99604 -0.054071 -0.0071187
0.42575 -0.054071 0.26255 -0.097088
0.056052 -0.0071187 -0.097088 0.98722
A(:,:,6,1) =
0.9818 -0.10286 0.085279 0.0034902
-0.10286 0.41855 0.48208 0.01973
0.085279 0.48208 0.60031 -0.016358
0.0034902 0.01973 -0.016358 0.99933
A(:,:,1,2) =
0.99071 -0.091198 0.0020814 -0.029755
-0.091198 0.10503 0.020426 -0.292
0.0020814 0.020426 0.99953 0.0066643
-0.029755 -0.292 0.0066643 0.90473
A(:,:,2,2) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
A(:,:,3,2) =
0.97125 -0.15889 -0.0080537 -0.051131
-0.15889 0.12194 -0.044507 -0.28256
-0.0080537 -0.044507 0.99774 -0.014323
-0.051131 -0.28256 -0.014323 0.90907
A(:,:,4,2) =
0.91488 -0.16388 -0.18495 0.12967
-0.16388 0.6845 -0.35607 0.24964
-0.18495 -0.35607 0.59815 0.28174
0.12967 0.24964 0.28174 0.80247
A(:,:,5,2) =
0.95461 0.16812 0.10326 0.066372
0.16812 0.37733 -0.38244 -0.24582
0.10326 -0.38244 0.76511 -0.15098
0.066372 -0.24582 -0.15098 0.90295
A(:,:,6,2) =
0.99628 0.012018 0.052874 0.027665
0.012018 0.96117 -0.17085 -0.089393
0.052874 -0.17085 0.24833 -0.39329
0.027665 -0.089393 -0.39329 0.79422
A(:,:,1,3) =
0.46769 0.019281 -0.49725 0.036486
0.019281 0.9993 0.018011 -0.0013215
-0.49725 0.018011 0.53551 0.034083
0.036486 -0.0013215 0.034083 0.9975
A(:,:,2,3) =
0.97125 -0.15889 -0.0080537 -0.051131
-0.15889 0.12194 -0.044507 -0.28256
-0.0080537 -0.044507 0.99774 -0.014323
-0.051131 -0.28256 -0.014323 0.90907
A(:,:,3,3) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
A(:,:,4,3) =
0.98622 0.043449 -0.066709 0.085142
0.043449 0.86297 0.21038 -0.26852
-0.066709 0.21038 0.67698 0.41227
0.085142 -0.26852 0.41227 0.47382
A(:,:,5,3) =
0.62859 0.041458 0.47558 0.074661
0.041458 0.99537 -0.053085 -0.0083339
0.47558 -0.053085 0.39105 -0.0956
0.074661 -0.0083339 -0.0956 0.98499
A(:,:,6,3) =
0.95505 -0.16608 0.12371 0.0067153
-0.16608 0.38639 0.45705 0.02481
0.12371 0.45705 0.65956 -0.01848
0.0067153 0.02481 -0.01848 0.999
A(:,:,1,4) =
0.96774 0.063488 -0.10826 0.12438
0.063488 0.87506 0.21304 -0.24477
-0.10826 0.21304 0.63673 0.41737
0.12438 -0.24477 0.41737 0.52047
A(:,:,2,4) =
0.91488 -0.16388 -0.18495 0.12967
-0.16388 0.6845 -0.35607 0.24964
-0.18495 -0.35607 0.59815 0.28174
0.12967 0.24964 0.28174 0.80247
A(:,:,3,4) =
0.98622 0.043449 -0.066709 0.085142
0.043449 0.86297 0.21038 -0.26852
-0.066709 0.21038 0.67698 0.41227
0.085142 -0.26852 0.41227 0.47382
A(:,:,4,4) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
A(:,:,5,4) =
0.73864 0.20112 -0.011394 0.39048
0.20112 0.84524 0.0087678 -0.30047
-0.011394 0.0087678 0.9995 0.017023
0.39048 -0.30047 0.017023 0.41662
A(:,:,6,4) =
0.87322 -0.15647 0.0029936 0.29363
-0.15647 0.80689 0.0036946 0.36238
0.0029936 0.0036946 0.99993 -0.0069332
0.29363 0.36238 -0.0069332 0.31996
A(:,:,1,5) =
0.7542 0.031217 0.42575 0.056052
0.031217 0.99604 -0.054071 -0.0071187
0.42575 -0.054071 0.26255 -0.097088
0.056052 -0.0071187 -0.097088 0.98722
A(:,:,2,5) =
0.95461 0.16812 0.10326 0.066372
0.16812 0.37733 -0.38244 -0.24582
0.10326 -0.38244 0.76511 -0.15098
0.066372 -0.24582 -0.15098 0.90295
A(:,:,3,5) =
0.62859 0.041458 0.47558 0.074661
0.041458 0.99537 -0.053085 -0.0083339
0.47558 -0.053085 0.39105 -0.0956
0.074661 -0.0083339 -0.0956 0.98499
A(:,:,4,5) =
0.73864 0.20112 -0.011394 0.39048
0.20112 0.84524 0.0087678 -0.30047
-0.011394 0.0087678 0.9995 0.017023
0.39048 -0.30047 0.017023 0.41662
A(:,:,5,5) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
A(:,:,6,5) =
0.93556 0.24481 -0.0093576 0.016177
0.24481 0.069855 0.035553 -0.061461
-0.0093576 0.035553 0.99864 0.0023492
0.016177 -0.061461 0.0023492 0.99594
A(:,:,1,6) =
0.9818 -0.10286 0.085279 0.0034902
-0.10286 0.41855 0.48208 0.01973
0.085279 0.48208 0.60031 -0.016358
0.0034902 0.01973 -0.016358 0.99933
A(:,:,2,6) =
0.99628 0.012018 0.052874 0.027665
0.012018 0.96117 -0.17085 -0.089393
0.052874 -0.17085 0.24833 -0.39329
0.027665 -0.089393 -0.39329 0.79422
A(:,:,3,6) =
0.95505 -0.16608 0.12371 0.0067153
-0.16608 0.38639 0.45705 0.02481
0.12371 0.45705 0.65956 -0.01848
0.0067153 0.02481 -0.01848 0.999
A(:,:,4,6) =
0.87322 -0.15647 0.0029936 0.29363
-0.15647 0.80689 0.0036946 0.36238
0.0029936 0.0036946 0.99993 -0.0069332
0.29363 0.36238 -0.0069332 0.31996
A(:,:,5,6) =
0.93556 0.24481 -0.0093576 0.016177
0.24481 0.069855 0.035553 -0.061461
-0.0093576 0.035553 0.99864 0.0023492
0.016177 -0.061461 0.0023492 0.99594
A(:,:,6,6) =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Edit 2:
Added relevant code. I've been pausing the code and getting the errors inside the for loops at the end. (I believe it's also giving errors in S, but I've been focusing on D trying to figure it out.)
mtimesx is from here.
n = 4;
M = 6;
P = Normalize(2*rand(n,1,M)-1);
%differences between p_i and p_j
%sum of p_i and p_j
d = Normalize(repmat(permute(P,[1,3,2]),[1,1,M]) - repmat(P,[1,M,1]));
s = Normalize(repmat(permute(P,[1,3,2]),[1,1,M]) + repmat(P,[1,M,1]));
d(isnan(d)) = 0;
%orthogonal projection onto d(:,i,j), i.e. outer product of differences
%orthogonal projection onto s(:,i,j), i.e. outer product of sums
D = mtimesx(permute(d,[1,4,2,3]), permute(d,[4,1,2,3]));
S = mtimesx(permute(s,[1,4,2,3]), permute(s,[4,1,2,3]));
D2 = D;
S2 = S;
%projection onto the complement of d(:,i,j)
%projection onto the complement of s(:,i,j)
D = repmat(eye(n),[1,1,M,M]) - D;
S = repmat(eye(n),[1,1,M,M]) - S;
%total distance to the nearest subspace
PDist = zeros([1,M]);
PDist2 = PDist;
for j = 1:M
for k = 1:M-1
for l = k:M
if j~=k && j~=l
PDist(j) = PDist(j) + min(norm(P(:,1,j) - mtimes(D(:,:,k,l),P(:,1,j))), norm(P(:,1,j) - mtimes(S(:,:,k,l),P(:,1,j))));
PDist2(j) = PDist2(j) + min(norm(D2(:,:,k,1)*P(:,1,j)),norm(S2(:,:,k,1)*P(:,1,j)));
end
end
end
end
PDist-PDist2
Normalize.m
%Normalize
%Accepts an array (of column vectors) and normalizes the columns
function B = Normalize(A)
B = A./repmat(sqrt(sum(A.*A)),size(A,1),1);
end
The problem is that you indexed the matrices using the constant 1 instead of the variable l (lowercase L), both in the first example and in the code for computing PDist2.
In general it is good to avoid using variable names that look similar to each other and/or similar to numbers.
This can be avoided by using an editor that highlights uses different colors for variables and constants (I don't know if this is possible in MATLAB). In fact, this is how I found the error in your code. As you can see, when indexing D2 for the computation of PDist2 the number 1 is colored red.

How to store values continuously without overwriting the previous one?

My project is "optical flow estimation for flame detection in videos" In that while extracting feature values, I can only retain the last intensity value of the frame.
Here is my code
function [Iy, Ix, It] = grad3D(imNew,bFineScale,bInitialize)
persistent siz gx gg imPrev;
if nargin>2 && bInitialize
[gx, gg]= makeFilters();
if bFineScale
siz = size(imNew);
imPrev= single(imNew);
else% if ~bFineScale
siz = floor(size(imNew)/2);
%initialize imPrev to half the size
imPrev = imresizeNN(single(imNew),siz);
end
end
if ~bFineScale
imNew = imresizeNN(conv2(single(imNew),gg,'same'),siz);
else imNew = single(imNew);
end
Ix = conv2(gg,gx,imNew + imPrev,'same');
Iy = conv2(gx,gg,imNew + imPrev,'same');
It = conv2(gg,gg,imNew - imPrev,'same'); %L3
% finally, store away the current image for use on next frame
imPrev = imNew;
testfeature = mean(imPrev);
save testfeature testfeature
[gx, gg]= makeFilters() x = (-1:1);
gg = single(gaussgen(0.67,3));
gx = single(-x.*gg*3);
In the highlighted coding(testfeature=mean(imprev)). I can be able to get only the intensity value of last frame extracted...But i need the values for all the extracted frames. I need the value to be stored row wise in a matrix file.

Getting current position of one of the multiple objects in a figure?

I wrote a script that returns several text boxes in a figure. The text boxes are moveable (I can drag and drop them), and their positions are predetermined by the data in an input matrix (the data from the input matrix is applied to the respective positions of the boxes by nested for loop). I want to create a matrix which is initially a copy of the input matrix, but is UPDATED as I change the positions of the boxes by dragging them around. How would I update their positions? Here's the entire script
function drag_drop=drag_drop(tsinput,infoinput)
[x,~]=size(tsinput);
dragging = [];
orPos = [];
fig = figure('Name','Docker Tool','WindowButtonUpFcn',#dropObject,...
'units','centimeters','WindowButtonMotionFcn',#moveObject,...
'OuterPosition',[0 0 25 30]);
% Setting variables to zero for the loop
plat_qty=0;
time_qty=0;
k=0;
a=0;
% Start loop
z=1:2
for idx=1:x
if tsinput(idx,4)==1
color='red';
else
color='blue';
end
a=tsinput(idx,z);
b=a/100;
c=floor(b); % hours
d=c*100;
e=a-d; % minutes
time=c*60+e; % time quantity to be used in 'position'
time_qty=time/15;
plat_qty=tsinput(idx,3)*2;
box=annotation('textbox','units','centimeters','position',...
[time_qty plat_qty 1.5 1.5],'String',infoinput(idx,z),...
'ButtonDownFcn',#dragObject,'BackgroundColor',color);
% need to new=get(box,'Position'), fill out matrix OUT of loop
end
fillmenu=uicontextmenu;
hcb1 = 'set(gco, ''BackgroundColor'', ''red'')';
hcb2 = 'set(gco, ''BackgroundColor'', ''blue'')';
item1 = uimenu(fillmenu, 'Label', 'Train Full', 'Callback', hcb1);
item2 = uimenu(fillmenu, 'Label', 'Train Empty', 'Callback', hcb2);
hbox=findall(fig,'Type','hggroup');
for jdx=1:x
set(hbox(jdx),'uicontextmenu',fillmenu);
end
end
new_arr=tsinput;
function dragObject(hObject,eventdata)
dragging = hObject;
orPos = get(gcf,'CurrentPoint');
end
function dropObject(hObject,eventdata,box)
if ~isempty(dragging)
newPos = get(gcf,'CurrentPoint');
posDiff = newPos - orPos;
set(dragging,'Position',get(dragging,'Position') + ...
[posDiff(1:2) 0 0]);
dragging = [];
end
end
function moveObject(hObject,eventdata)
if ~isempty(dragging)
newPos = get(gcf,'CurrentPoint');
posDiff = newPos - orPos;
orPos = newPos;
set(dragging,'Position',get(dragging,'Position') + [posDiff(1:2) 0 0]);
end
end
end
% Testing purpose input matrices:
% tsinput=[0345 0405 1 1 ; 0230 0300 2 0; 0540 0635 3 1; 0745 0800 4 1]
% infoinput={'AJ35 NOT' 'KL21 MAN' 'XPRES'; 'ZW31 MAN' 'KM37 NEW' 'VISTA';
% 'BC38 BIR' 'QU54 LON' 'XPRES'; 'XZ89 LEC' 'DE34 MSF' 'DERP'}
If I understand you correctly (and please post some code if I'm not), then all you need is indeed a set/get combination.
If boxHandle is a handle to the text-box object, then you get its current position by:
pos = get (boxHandle, 'position')
where pos is the output array of [x, y, width, height].
In order to set to a new position, you use:
set (boxHandle, 'position', newPos)
where newPos is the array of desired position (with the same structure as pos).
EDIT
Regarding to updating your matrix, since you have the handle of the object you move, you actually DO have access to the specific text box.
When you create each text box, set a property called 'UserData' with the associated indices of tsinput used for that box. In your nested for loop add this
set (box, 'UserData', [idx, z]);
after the box is created, and in your moveObject callback get the data by
udata = get(dragging,'UserData');
Then udata contains the indices of the elements you want to update.

Resources