2D Matrix, Compacting problem

Hi!
I'm about to implement a matrix class that need som kind of "compacting" support, meaning:
If the the following matrix (3x4) is compacted:
[1][0][2][8]
[7][0][3][9]
[0][0][0][0]
The resulting matrix (2x3)would be:
[1][2][8]
[7][3][9]
Column 2 will be removed since it's empty (only zeros)
and row 3 will be removed as well sinces its empty.
I've tried a number of solutions, but they are all inneficient and/or cumbersome.
I'm thinking like this:
Find out which rows and columns should be removed.
Create a new matrix with the new size, and iterate over the first matrix copying the values.
Any ideas that come to mind?
What about choice of datastructure?
Is the best I can do to use a long[][] or maybe a
combination of Lists of some sort?
Any ideas for the algorithm?
Oh, the size of the matrix will in most of the times be around 80x80 to maybe 120x120 (not necessarily same rowcount as colcount)
And it must support getting/adding at specific cells, because of the way it's filled with values (from database)
/ Ronnie

Find out which rows and columns should be removed.Well, that's easy. Two arrays of booleans, initially all false, iterate through the entire matrix setting appropriate booleans to true if you find a non-zero element.
Create a new matrix with the new size, and iterate over the first matrix copying the values.Convert each array of booleans into an array of ints, which are the subscripts of the boolean arrays which were true. E.g. {f, t, ,t f, t} -> {1, 2, 4}.
The sizes of these arrays give the matrix size. Two nested loops to copy elements across.

Similar Messages

  • Can you help me to solve this matrix filling problem?

    Hi,
    I need to fill a matrix column. this is the description briefly.
    1.This is my binding
    oForm.DataSources.UserDataSources.Add("usr_col5", SAPbouiCOM.BoDataType.dt_DATE, 50);
    oColumn = oColumns.Add("Col5", SAPbouiCOM.BoFormItemTypes.it_EDIT);
                    oColumn.Description = "Konteringsdato";
                    oColumn.TitleObject.Caption = "Konteringsdato";
                    oColumn.DataBind.SetBound(true, "", "usr_col5");
                    oColumn.Width = 89;
                    oColumn.Editable = false;
    2.I am going to fill this column using record set's field. all of the other column's fillings are ok.but problem is here
    oForm.DataSources.UserDataSources.Item("usr_col5").Value = oRs.Fields.Item("DocDate").Value.ToString();
    I think there should be a casting instead of of using ToString(). But i couldn't able to do it. So please help me.

    Hi,
    you can try once to set
    ((SAPbouiCOM.EditText)((SAPbouiCOM.Matrix)(oForm.Items.Item("mtxItemUID").Specific)).Columns.Item("Col5").Cells.Item(cellnumber).Specific).String = oRs.Fields.Item("DocDate").Value.ToString();
    or
    ((SAPbouiCOM.EditText)((SAPbouiCOM.Matrix)(oForm.Items.Item("mtxItemUID").Specific)).Columns.Item("Col5").Cells.Item(cellnumber).Specific).Value = oRs.Fields.Item("DocDate").Value.ToString();
    regards
    David

  • Matrix addrow problem

    I want to enter some value in a matrix
    I enbled matrix with
    oMatrix.AddRow()
    but problem is
    that - when I am inputing data in matrix fields , after pressing tab the value disappears
    how can I resolve the problem?

    thts because your matrix's columns are not bound with any user or DB datatsource. alternatively , you will have to bind it with the columns of table to which you are saving the data.
    regards,
    Binita

  • Group Matrix Report Problem

    when i build a group matrix report ,i only able to get the summary totals of columns (in the cross product ) at group level,but fail to get the summary totals of columns (in the cross product) at report level.So please tell me , how can i achieve this one?

    Dear Waheed....I think u just have to set property of summary column
    'Reset at = Report'
    I this does'nt work then u should explain ur problem.
    Kashif

  • Crystal Repoorts 2008 W2008R2 Dot Matrix Printing Problems

    Using CR2008 running on Windows Server 2008R2 - printing toLexMark 2580n dot matrix printers.
    I have developed reports that print correctly WHEN I call them up in Crystal Reports 2008 and print them from that application. If I call that same report from within a Visual Studio application, it does not print at all as expected (or desired!!). Similarly, I cannot get other reports to print correctly running directly out of Crystal yet if I call them from the Visual Studio application it does work/behave.
    Also, I have some label reports that are printing to a 3.5"W x 2.0"H size (I created a custom label like usual in printer server properties) that behave when I run them directly from Crystal but consistently print out vertically (90 degrees to the right) when I run it from Visual Studio. It's maddeming. I tested the reports when I first purchased CR2008 to make sure it would run on W2008R2 Server (and it did work). Did not see this problem coming. Any assistance would be helpful.
    FYI I am printing to LexMark 2580n dot matrix, brand new printers (had to purchase these to make drivers work on W2008R2). LexMark has effectively (to my satisfaction) ruled out their printers as the problem.
    Any advice would be greatly appreciated.

    Links to SP 4:
    SP4     https://smpdl.sap-ag.de/~sapidp/012002523100008782452011E/cr2008sp4.exe
    SP4 MSI     https://smpdl.sap-ag.de/~sapidp/012002523100008782532011E/cr2008sp4_redist.zip
    SP4 MSM     https://smpdl.sap-ag.de/~sapidp/012002523100008782522011E/cr2008sp4_mm.zip
    Ludek

  • Udo matrix -save problem

    Hi,
    i am creating a form by using UDO form generator.
    in that documet and doucument rows are existed. if user select the combobox value from the form, by taking that value and i am generating a query, i am generating a recordset. by using Userdatasources i am binding each column in matrix.
    i binded all values to the matrix successfully. but
    but when i press Add button, this matrix rows are not getting saved. and also if i have two rows, when i press add, in database only one row is adding with NULL values. how to save that matrix data?
    please help me urgent
    asap
    regards,
    nagababu

    I believe this is a duplicate of
    Udo matrix rows saving problem
    Pls read the guidelines. Don't duplicate requests, this just cause confusion and
    inefficiency in the forum. And pls remember that this is a community of very very
    busy developers, each of them with his/her "urgencies" ....

  • Matrix CFL problem

    Hello
    I have a following problem:
    I want to make one column in matrix editable and CFL(from OITM).
    If I bind it with userdatasource, the chosen value cannot be changed later.
    If I bind it with DBdatasource, when I choose the proper value in CFL, I get an error :Bad form Value.
    I made very similar thing but not with columns(with form items) and then I could bind an item with EditText field and everything was cool.  edittext1 = (SAPbouiCOM.EditText)oItem.Specific;
    But now I cannot convert a column to EditText object 
    Anybody help me, please?

    Could you send me more code to look for the problem?
    Regards,
    J:

  • Xperia z1 compact problem restoring

    Hello. I've bought new sony xperia z1 compact but it has a serious problem. Every time I plug it in (to charge) it restores. The promo video keeps playing again and again, my wallpaper disappears and sets default and the worst thing is that all my photos I took before are deleted. (photos from whatsapp and messenger remain, music remains and gmail, whatsapp and viber remain logged in) All this used to happen when I plugged the mobile to charge but the last time it happened itself suddenly.Please, can you tell me what it is caused by and what can I do about it? In this moment I do not reside at the same place I bought the phone at so I am not able to return it. Thank you very much.

    Hi boavista,
    Welcome to the community,
    This sounds like the device is set to Demo mode, you can try removing this by doing the following.
    *#*#73556673#*#*
    This should remove the demo mode, let us know how you get on.

  • Option + Drag notes in Matrix editor problem

    I cant say when this started but at some point holding option while dragging a note to copy it stopped working as expected. Basically I want to copy a note in the matrix editor and I want it to go where I drag it (am I asking too much?). Right now as soon as I drop the note in the desired position it jumps forward several beats. Did I do something that changed the way the option key works? If I just drag the note without holding option the note goes where I want it. But as soon as I option + drag. I get this wackyness!! its hugely frustrating! Thanks in advance for any help.

    Well I have a workaround now but am still confused. I discovered that if I click the little button "featuring a square graphic" in the upper left corner of my matrix window (manual says its called the "Up One Display Level button—or
    UDL button"), it fixes the problem... for that matrix edit window only. As soon as I close it and reopen it (by double clicking on a midi region) it goes back into crazy freak **** mode. Something else I noticed is that when I reopen the matrix editor window the little screen read out area (that displays the notes etc under Edit/Functions/View) says "sel 1" right above the notes etc. It says this when its in crazy freak **** mode. When I click the UDL button it changes from "sel 1" to "1/AudioInst 1" which is the instrument for the midi Im working on. So how do I get crazy freak **** mode to stop messing up my matrix editor windows? Its great to have a workaround but its a pain in the butt to have to remember to push this button ( that I never needed to push before) so I can properly option+drag a midi note. I tried reading the manual about this button but I just dont get what its for (other than turning off freak **** mode). And I forgot to mention my logic version before: Logic version 7.2.1 (959.30) Thanks again in advance if you can help me:)

  • Printing using dot matrix printer,problem with landscape printing

    Hi all,
    We are planning to use Dot matrix printers for printing through SAP.We do front end printing using Windows OS. I am able to get prints properly if it is a script form. In case of list outputs, printer is printing the text outside the paper.Only half of the text is printing on the continuous stationary. Actually document is to be printed in Landscape format. So printer should print data vertically on the paper,but it's printing horizontally. I have created sparate output device for this printer.My printer is TVS Electronics HD745 24 Pin heavy duty printer. I have assigned OKI341 as device type for this device.Any more settings I need to do to get printing in landscape mode?

    closing thread

  • Matrix-binding problem

    Hi,
    I created one UDO form.
    in that i am trying to fill the matrix with recordset.
    becoz i am selecting the value from combobox and i run the query with this value.
    so this resultant record set i want to fill in matrix rows.
    oForm = SBO_Application.Forms.Item("JBWISSUES_")
    oItem = oForm.Items.Item("mtx_0")
    oMatrix = oItem.Specific
    oColumns = oMatrix.Columns
    'frm = app.Forms.ActiveForm
    'oMat = frm.Items.Item("gd_act").Specific
    'oMatrix.Clear()
    oComboBox = oForm.Items.Item("27").Specific
    ds = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
    ds.DoQuery("select a.code as Code,b.Itemname as Desc1,a.quantity as Quantity from itt1 a,oitm b where a.code=b.Itemcode and a.code='" & oComboBox.Selected.Value & "'")
    ds.MoveFirst()
    oColumn = oColumns.Item("col_0")
    For i = 0 To ds.RecordCount - 1
    oColumn.ValidValues.Add(ds.Fields.Item("Code").Value, ds.Fields.Item("Desc1").Value)
    ds.MoveNext()
    Next
    oMatrix.AddRow()
    here i am getting error like Object reference not set to instance error at oColumn.validvalues....... plz hel p me in that.
    Regards,
    Ravi

    Hai Ravi,
                U try this coding..........Write the function to fill the matrix with combo and then call this function in combo select event........
    Sub LoadGridCombo()
            Dim oMat As SAPbouiCOM.Matrix
            Dim oCol As SAPbouiCOM.Column
            Dim oCmb As SAPbouiCOM.ComboBox
            Dim ds As SAPbobsCOM.Recordset
            Dim i As Integer
            Try
                frm = app.Forms.ActiveForm
                oMat = frm.Items.Item("gd_act").Specific
                oMat.Clear()
                oCmb = frm.Items.Item("cmb_dept").Specific
                ds = com.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                ds.DoQuery("Select Code,U_Activity from [@PLANT_ACTIVITY] where U_dept='" & oCmb.Selected.Value & "'")
                ds.MoveFirst()
                oMat = frm.Items.Item("gd_act").Specific
                oCol = oMat.Columns.Item("g_act")
                If oCol.ValidValues.Count > 0 Then
                              For i = 0 To ds.RecordCount - 1
                    oCol.ValidValues.Add(ds.Fields.Item(0).Value, ds.Fields.Item(1).Value)
                    ds.MoveNext()
                Next
    End If
                oCol = oMat.Columns.Item("g_freq")
                If oCol.ValidValues.Count = 0 Then
                    oCol.ValidValues.Add("1", "Annually")
                    oCol.ValidValues.Add("2", "Semi Annually")
                    oCol.ValidValues.Add("3", "Quarterly")
                End If
                oMat.AddRow()
            Catch ex As Exception
                app.MessageBox(ex.Message)
            End Try
        End Sub
    Regards,
    Anitha

  • Matrix Report Problem in Oracle Apps

    Hii All,
    I have created a matrix report in Orace Application using Oracle 6i. It running properly in Report 6i. But after registering in Oracle Apps,
    It does not shows any output.
    Database 10g
    Report 6i
    EBS Oracle 11i
    Thanks
    PS

    Hi PS
    Please check below links:
    How to create a matrix report
    How to create a matrix report
    how to build matrix report
    how to build matrix report
    Oracle Reports Building Reports
    http://download.oracle.com/docs/html/B10602_01/part4.htm
    Regard
    Helios

  • Filevault compaction problem

    I have been using filevault and it won't compact my files.
    I have tried the hdiutil compact command but all that happens is that I get a "permission denied" response.
    Any ideas?
    Here's what happens in Terminal:
    hdiutil compact /Users/pete/pete.sparseimage
    Initializing...
    Attaching...
    Finishing...
    hdiutil: compact failed - Permission denied

    I have been using filevault and it won't compact
    my files.
    What gives you that idea? Why would you want to do
    that? See Help->FileVault on how it works.
    Ummmm..... probably because when I delete files the amount of spare space on my hard drive doesn't get any larger, eg deleted 10GB of music but only 7GB is free
    I have tried the hdiutil compact command but all
    that happens is that I get a "permission denied"
    response.
    Normal behavior, especially with an encrypted
    sparseimage. The answer is to precede the hdiutil
    command with sudo, but I strongly suggest you resist
    that urge until you fully comprehend what you're
    trying to do. See my first response.
    I'll meditate on that
    Finally, which national security items are you trying
    to protect with FileVault? I do not support its use
    for home users or benign office users. There are
    better solutions. See, for example,
    http://discussions.apple.com/thread.jspa?threadID=7790
    98.
    I agree, unfortunately I turned it on and now can't turn it off. Filevault tells me I need another 4000GB of free space in order to decrypt my hard drive.

  • Rdf matrix report problem

    Hi all, i want a solution from you guys.
    I have a rdf report where size is shown there (like S, L, M, XL, XXL...etc). Later i have another matric report
    SERIAL SIZE
    1 Small
    2 Mediam
    3 Large
    4 Extra-Large
    5 Double-Excel
    now i want to make a matrix report where matrix column is SIZE . But mu concern is, i want to show them the sequence of SERIAL.
    How can i do that ...?

    replied you here:
    Matrix Roport Calculation Problem

  • Z1 compact problem

    For those who do not call my voice !!! What to do ?

    leher wrote:
    For those who do not call my voice !!! What to do ?
    Sorry, can you explain what the problem is a bit more......are you gtalking about Voicemail 

Maybe you are looking for