I am trying to create a excel file from Matlab with data for multiple cases. The excel file should look something like this:
Case #|____________________________Line 1_____________________________________________|_______ Line 2 _____________ ...
|______Node 1______|______Node 2______|______Node 3______|...|______OverAll_____|
| Min|Max|Mean|Std | Min|Max|Mean|Std | Min|Max|Mean|Std |...| Min|Max|Mean|Std |
|_______________________________________________________________________________|
1| | | | | | | | | | | | | | | | |
2| | | | | | | | | | | | | | | | |
I have the data for each Line>Node in a structured format which I can read through a for loop for a given case. How can I write the values in an excel file? I don't know how to get the next available cell range where I need to place the value. Also, how can I generate such header text dynamically. The number of Nodes and properties (Min/Max/Mean/Std) might change in future.
Thank you for your help. Any suitable tutorial which teaches little advanced xlswrite commands will also help.
Use Activexserver to import whole Excel Functionality in MATLAB using
hApp = actxserver('Excel.Application')
Rest you can use all methods available to Excel Application in MATLAB
Related
Consider a spreadsheet with a "source" spreadsheet and a "formatted" sheet
The formatted sheet references data from a source sheet.
The ideal way for this to work is to use array formula
# formatted-sheet (formulas)
| title | description |
------------------------
| = ArrayFormula(source!A2:AA) | |
| | |
| | |
# source (raw data)
| title | description |
------------------------
| SomeTitle | long description |
| OtherTitle | Other description |
| emptyDesc | |
In google spreadsheet, the resulting formatted sheet displays like this :
# formatted-sheet (rendering formulas)
| title | description |
------------------------
| SomeTitle | long description |
| OtherTitle | Other description |
| emptyDesc | |
However after exporting to Excel format, the empty values are displayed as "0"
# formatted-sheet (rendering formulas)
| title | description |
------------------------
| SomeTitle | long description |
| OtherTitle | Other description |
| emptyDesc | 0 |
| 0 | 0 | # for every additional line captures by the array formula, zeroes everywhere
The fix I found for this, is to use an IF to check for empty string values
# formatted-sheet (formulas)
| title | description |
------------------------
| = ArrayFormula(IF(source!A2:AA = ""; ""; source!A2:AA)) | |
| | |
However the IF() formula is broken for cells that are longer than 255 characters, Is there a different workaround possible ?
Foe example a way to rpevent the empty strings to appear as "0" after exporting to xlsx and opening with Microsoft Excel ? or to improve the formula ?
Here is the reference for a sample sheet.
Try using:
=ARRAYFORMULA(IF(NOT(ISBLANK(source!B2:B)),source!A2:AA,""))
it also hides the last "emptyDesc". If this is not your intention please let me know.
I found out this trick from this question that is quite concise to convert everything to a text like format.
=ArrayFormula(source!A2:AA & "")
However it will most likely kill the formatting of numbers and interoperability, I have not made extensive tests regarding this, as it is fine for me in the current state
Alright, I'm back. This time I'm trying to quickly select all of the values in a range which match values in a separate list, my first iteration will be to clear the contents of voided IDs, my second iteration will be to select those values and then replace them with corresponding new values.
I asked another question about VBA and was pointed in mentioning that I've tried to teach myself and find resources to work through these issues before but people seem to get pissed that I'm asking, if you could at least direct me to somewhere that I can learn about these matters (or even a place I can learn basic logic and have a list of usable functions without having to go through all the "How to make your first Excel VBA for some problem that nobody cares about" I would appreciate it)
Anyway I tried to watch a few videos and then hack together something but it seems pretty clear that the function they were using cannot be adapted for other uses. This is what I have at the moment:
Sub FilterElim()
finalRow = Range("g2").End(xlDown).Row
Range("A1").ClearContents _
Action:= xlClearContents, _
CriteriaRange: Range("Sheet4!B1:B10"), _
Unique:= False
End Sub
So based on some helpful questions I am making an edit to include an example and desired end
Example set:
Desired end result:
I presume I may need to perform a selection of some sort based on the Criteria before the ClearContents but I wasn't finding anything helpful on how to go about that. PLEASE and thank you.
| Contractor ID | Cont Name | Proj 1 | Proj 2 | Proj 3 | | | Old ID | Reconciliation |
|-----------------|-------------------|--------|--------|--------|---|---|--------|----------------|
| C1001 | Boba Fet | P1120 | | | | | P1001 | Void |
| C1003 | Jules Winnfield | P1031 | P1045 | | | | P1002 | P1010 |
| C1002 | Dom Cobb | P1001 | | | | | P1005 | Void |
| C1010 | Patrick Verona | P1020 | P1224 | P1251 | | | P1020 | Void |
| C1007 | Matt Damon | P1008 | P1005 | P1300 | | | P1045 | P1100 |
| C1004 | Ned Plimpton | P1002 | | | | | P1224 | P1300 |
| C1020 | Derek Zoolander | P1020 | P1290 | | | | | |
| C1009 | Charles Marlow | P1002 | P0090 | | | | | |
| C1011 | Robert Jordan | P1119 | | | | | | |
| C1015 | Perrin Aybara | P1200 | P1224 | | | | | |
| C1005 | Fuzzy Dunlop | P1005 | | | | | | |
| C1008 | Thomas A Anderson | P1001 | P1000 | | | | | |
| | | | | | | | | |
What makes you go for a VBA solution ?
Hard to do much without a glance of you data and expected result.
Non VBA option:
=IFERROR(INDEX($G$2:$G$15,MATCH(A32,$F$2:$F$15,0)),B32)
For a VBA option, you can try:
Option Explicit
Sub update_id()
Dim D1 As Object: Set D1 = CreateObject("scripting.dictionary")
Dim R1 As Range: Set R1 = Range("A2:A32")
Dim R2 As Range: Set R2 = Range("E2:E15")
Dim Rtmp As Range
For Each Rtmp In R2
D1(Rtmp.Value) = Rtmp.Offset(0, 1).Value
Next Rtmp
For Each Rtmp In R1
If D1.exists(Rtmp.Value) Then Rtmp.Offset(0, 1) = D1(Rtmp.Value)
Next Rtmp
End Sub
Working on the following set up :
Again, without a better understanding of your data and your issue, its hard to be more precise.
I've been trying to use AVERAGE with INDIRECT but keeps giving me errors.
Now I am using Average like this:
AVERAGE(Results!C2:C51)
I need to get data from another sheet "Results". But in my current sheet I got the range of the rows set in two cells.
+-------------------+
| ... E F |
| +-------+-------+
| 2 |...| 2 | 51| |
| +---------------+
| 3 | | 52|101| |
| +---------------+
| 4 | | | | |
+---+---+---+---+---+
I've tried like this, but it's not working:
AVERAGE(Results!INDIRECT("C"&E2):INDIRECT("C"&F2))
This should do it:
=AVERAGE(INDIRECT("Results!C"&E2&":C"&F2))
The answer posted by zipa is correct. Here is an alternaive that will allow you to avoid INDIRECT() entirely:
=AVERAGE(INDEX(Results!C:C,E2):INDEX(Results!C:C,F2))
This is based on Scott Craner's Answer to a question I asked previously.
I have a large list of users with various codes. The goal is to separate the good from the bad. All codes that start with P, H or F are good. All codes that start with L or K are bad. Example:
Email | Code 01 | Code 02 | Code 03 | Code 04 | RESULT
user01#gmail.com | PJR-VRF | | | | GOOD
user01#gmail.com | | LNR-JNT | | LNR-JNT | BAD
user01#gmail.com | | HVB-YWQ | HVB-YWQ | HVB-YWQ | GOOD
user01#gmail.com | | LNR-JNT | | KVB-MMO | BAD
user02#gmail.com | | | | PHH-KLP | GOOD
user02#gmail.com | | HNR-OPT | | LNR-JNT | GOOD
user02#gmail.com | | FLT-MWQ | | FLT-MWQ | GOOD
user02#gmail.com | | KVB-MMO | KVB-MMO | KVB-MMO | BAD
In other words, if a range contains any cells that begin with P, H, or F then good, otherwise bad. I've tried to use the following formula in the result column:
=IF(COUNTIF(B2:E2,{"H*","P*","F*"}),"good","bad")
It didn't work unfortunately, so I tried this:
=IF(COUNTIF(B2:E2,"H*") + COUNTIF(B2:E2,"P*") + COUNTIF(B2:E2,"F*"),"good","bad")
This seems to work, but is this the best method? Say I have 20 other conditions to check against? And need to add a third result? What is the best approach to sift this data?
You can use an array formula similar to this:
=IF(SUM((--($B2:$D2<>""))*(--ISNUMBER(FIND(LEFT($B2:$D2,1),"HPF"))))>0,"GOOD","BAD")
Please remember to press Ctrl+Shift+Enter to complete the array formula correctly.
If you need to add a third result:
=IF(SUM((--($B2:$D2<>""))*(--ISNUMBER(FIND(LEFT($B2:$D2,1),"HPF"))))>0,"GOOD",IF(SUM((--($B2:$D2<>""))*(--ISNUMBER(FIND(LEFT($B2:$D2,1),"EKD"))))>0,"OTHER","BAD"))
I usually have my Vim screen split into two vertical windows, each of which may be further horizontally split. Sometimes, I want to add or delete a vertical window. Is there a way to detect how many top-level vertical splits there are and add or remove vsplits as necessary?
For example, suppose my screen looks like this:
+--------+--------+
| | |
| | |
+--------+ |
| | |
| | |
| +--------+
| | |
+--------+--------+
I want :Columns 1 to give me
+--------+
| |
| |
+--------+
| |
| |
| |
| |
+--------+
by closing the two right-most windows.
I want :Columns 2 to do nothing, detecting that two columns are already open.
And I want :Columns 3 to give me
+--------+--------+--------+
| | | |
| | | |
+--------+ | |
| | | |
| | | |
| +--------+ |
| | | |
+--------+--------+--------+
I am fine if the function ignores vertical splits within horizontal splits. For example, if I had
+--------+
| |
| |
+---+----+
| | |
| | |
| | |
| | |
+---+----+
and I ran :Columns 2, I would get
+--------+--------+
| | |
| | |
+---+----+ |
| | | |
| | | |
| | | |
| | | |
+---+----+--------+
There is indeed a way, but it is involved; the first step is to count the currently-open vertical windows, and I don’t know of any built-in function that facilitates this. The working approach I found to it is basically to start at the first window (the top of the first — if not the entirety of the first — vertical split), and to then, using wincmd l, move to the next window to the right for as long as wincmd l moves to a new window, adding each to a count of open vertical windows including the first one. (I think this is what Gary Fixler referred to in the comments on the question.)
I started trying to write the code for posting here, and it grew to become larger than any function I would want to put in my ~/.vimrc, so I ended up turning it into a plugin which takes the above approach and provides the :Columns command; see Columcille (on vim.org at http://www.vim.org/scripts/script.php?script_id=4742.) The plugin also provides a command for similarly managing horizontal split windows: :Rows divides the current column (or the main window, if there are no open vertical splits) into the specified number of “rows.”