i have a code that works on all files in folder and analyise it and come then export results into excel sheet.
My question is, by the end i alot of excel sheets and i need to combine them all together (i also need them separate) so i do this manualy and its really painfull and time wasting !
So i want to ask is there a way to create an array to save the results of each analysis my code process and export all at the end to one excel file.
Example of my code Workflow:
Read files in current dir
Open files one by one.
Do math equations and get results into 2 arrays amp[] signal[] (both are equal in size)
Export results into Excel using
xlswrite([b '.xls'],[amp' signal'],1);%%b=file name (example.avi ==> example.avi.xls)
And so on.
So i want to save the results after that to array with the filename and at the end past all into 1 excel sheet with the file name on top of each column :)
I dont know why i'm having a brain block on how to do it !
Thanks alot for your help in advance
Xlswrite supports that you give a start point or range where you want to put your data. See Xlswrite.
You can quickly calculate the column name using this.
But you must be aware that excel only supports 255 columns and 1024 rows in a sheet. This happened often to me and then one gets a very uninformative error.
Related
I am new to Python and am over complicating the coding on a project so I am starting with much smaller data sets in order to learn the process. My boss is having me compare two CSV files. The first CSV only contains the data 1,2,3,4,5,6 all in a single column. He wants me to set this CSV file as an array so I can compare the second CSV against it. The second CSV contains the data 3,5,6 all in a single column. The code should result in a print out of 1,2,4 as it is the only data not found in both CSV files.
I originally tried to write a code to import both CSV files and compare data without setting it as an array but this did not work so the first CSV file needs to be set as an array. The problem is I am not sure exactly how to do this with an array. This is what I have so far, any help anyone could give me would be greatly appreciated. I have been working on this project for a week now and am at a total loss, even with this simplified form.
import csv
temp_list = []
with open('1.csv','rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
In terms of psuedo-code, what you need to do here is import both csv files into two separate arrays, Array A and Array B for example.
Now what you need to do is compare each index position in one array, to each index position in the other array.
You need to create a nested loop, where the outer loop will choose an index position in A and then inner loop chooses a position in B.
After you check one index in A with each position in B, and no positions are the same, I suggest adding this value into a third array, C. You can check which positions are the same by using a boolean flag. When your code is done, C will have any values that don't exist in both A and B.
I suggest following these tutorials to learn more about python syntax:
https://www.w3schools.com/python/
Good luck
I know that I am pretty confused about arrays and strings and have tried a bunch of things but I am still stumped. I have groups of data that I am pulling into various arrays. For example I have site locations coming from one source. Numerous cores can be at a single location. The cores can have multiple depths. So I am pulling all this data together in various ways and pushing it out into a single excel file for each core. I create a filename based on location id and core name and year the core was sampled. So it might look like ‘ID_14_CORE_Bu-2-MT-1991.xlsx’ and I am storing it to use with a xlswrite statement in a variable called “filename.” This is all working fine.
But now I want to keep track of what files I have created and when I created them in another EXCEL file. So I was trying to store the location, filename and the date it was processed into some sort of array so that I can use the xlswrite statement to push it all out after I have processed all the locations/cores/layers that might occur in the original input files.
As I start the program and look in the original input files I can figure out how many cores I have so I wanted to create some sort of array to hold the location, filename and the date together. I have tried to use a cell array (a = cell(numcores,3)) but that does not seem to work. I think I am understanding that the filename is actually a string array so each of the letters is trying to be assigned to a separate cell instead of just the cell in the second column.
I also have had problems trying to push the three values out to the summary EXCEL file as each core is being processed but MATLAB tends to treat single dimensional arrays as a row rather than a column so I am kind of confused there.
Below is what I want an array to end up like…but since I am developing the filename on the fly this seems to be more challenging.
ArraytoExcel = [“14”, “ID_14_CORE_Bu-2-MT-1991.xlsx”,”1/1/2018”;
“14”, “ID_14_CORE_Bu-3-MT-1991.xlsx”,”1/1/2018”;
“13”, “ID_13_CORE_Tail_33-1992.xlsx”,”1/1/2018”;]
Maybe I am just going about this the wrong way. Any suggestions would help.
Your question is a little confusing but I think you want to do something like the following. The variables inside of my example are static but from your question it sounds like you already have these figured out somehow.
numcores = 5; %.. Or however, you determine what you are procesing
ArraytoExcel = cell(numcores ,3);
for ii = 1:numcores
%These 3 things will need to determined by you in the loop
% and not be static like in this example.
coreID = '14';
filename = 'ID_14_CORE_Bu-2-MT-1991.xlsx'; %
dataProc = datestr(now,'mm/dd/yyyy');
ArraytoExcel(ii,:) = {coreID,filename,dataProc};
end
xlswrite('YourOutput.xls',ArraytoExcel)
I am at my tethers end on a question and was hoping someone on here could point out the simple mistake I am making.
I have a formula that I am using in an excel spreadsheet that works fine but when I import into Google Sheets it ceases to work.
The formula that works in excel is
{=INDEX('2009-2010'!D2:D20,MIN(IF(SUBTOTAL(3,OFFSET('2009-2010'!D2,ROW('2009-2010'!D2:D20)-ROW('2009-2010'!D2),0)),ROW('2009-2010'!D2:D20)-ROW('2009-2010'!D2)+1)))}
and the way I try and use it in sheets is
=ArrayFormula(INDEX('2009-2010'!D2:D20,MIN(IF(SUBTOTAL(3,OFFSET('2009-2010'!D2,ROW('2009-2010'!D2:D20)-ROW('2009-2010'!D2),0)),ROW('2009-2010'!D2:D20)-ROW('2009-2010'!D2)+1))))
But instead of doing what it is meant to (which is displaying the top visible cell on column 'D' of another worksheet called '2009-2010') it just inserts the whole column.
I have tried a couple work arounds but I am in over my head - any assistance would be fantastic!
Somewhat surprisingly I have not been able to find anything(anywhere) about someone trying to do the same function on Google Sheets...?!
This is an oldie, but if someone is still interested one could use this formula instead, in both Excel and Spreadsheet:
=INDEX('2009-2010'!D2:D20,MIN(IF('2009-2010'!D2:D20>0,ROW('2009-2010'!D2:D20)-ROW('2009-2010'!D2)+1)))
The IF('2009-2010'!D2:D20>0 part can also be changed to <>"" if the values are texts.
The problem is Spreadsheet doesn't treat all array formula scenarios the same way Excel does. For example Excel calculates the CountA for each item and returns an array of 0 and 1, and Spreadsheet counts the whole array and returns one count result.
This formula is also more efficient by avoiding the OFFSET volatile function.
What I'm in need of is somewhat complicated and challenging, an I don't know anywhere else to ask for help. I have several excel files, named like thb201301221.xls,thb20130201.xls , and the naming convention used in these files are like thb + date of the file created + (1 or 2). In each file, there are several sheets. I'm interested in certain sheets, named as N1-1, N1-2 AND N1-3. What I need to do is:
Combine these N1-1, N1-2 AND N1-3 sheets into one sheet for all
workbooks
Add a column to beginning of each of these sheets and fill it with
the date in the workbook name (in the file thb201301221.xls it's
22.01.2013)
Create a workbook and a worksheet within it and fill it with these
newly created worksheets, which are combination of N1-1, N1-2 AND
N1-3 sheets in the workbooks.
Can someone help me in achieving this task. I can't possibly thinking of doing this manually and I'd really appreciate for your help.
Thanks already,
Korhan
You will not get a question like this answered here. You have asked for too much in one go and you have not shown a minimal understanding of how to solve the problem. We are here to help you improve your code not write it for you.
Break your total problem down into steps 1, 2, 3, ... N. Write macros that perform step 1, step 1 and 2, step 1, 2 and 3 and so on. If you have trouble with step X then ask about step X and show us the code that does not do what you expect.
EDIT IN my original answer I said I could go further than step 3 without knowing more. Do you want all the N1-1, N1-2 and N1-3 worksheets combined into a single worksheet or will you have three separate worksheets? I later realised that I could go further if I was vague about worksheet names.
My steps for your problem :
Create a list of the workbooks of interest.
If sequence is important, is that list in the correct sequence? If Yes and No, sort the list.
Add an empty workbook to the Workbooks collection ready to receive the combined data.
Rename worksheeet "Sheet1" and other worksheets as necessary.
Loop through the [sorted] list of workbooks, opening each workbook, copying the required information from the source to destination worksheets and closing the workbook
For step 1, you will need either the Dir$ function or the Files property of the Folders Object. You should be able to find either using the Visual Basic Help. Dir$ is the older function and is probably easier to understand. Folder Objects and their properties (for example Files) are more flexible and complete but may be harder to understand. Note: Dir and Dir$ look the same but Dir$ is marginally more efficient.
Get each workbook name and use Debug.Print FileName to prove you have got the workbooks you want. If your code for step 1 does not work, ask a question about it.
If you need to sort the list, search for "excel vba sort an array".
Next search for "excel vba add an empty workbook to the Workbooks collection".
For step 5 you will need to use the Copy statement which looks like: RngSource.Copy Destination := RngDestination. You will need to identify the size of the source range and specify RngSource. The Destination range will be the same size but the first row will be one more than the last row used and the first column will be 2 not 1 so you can fill in column 1 with the date from the filename.
I hope you get the idea. If your steps are small enough and well defined enough, you should have no difficulty in finding some suitable code to add to your growing macro. If you run into difficulties, a small question here will usually yield something helpful.
So I have a huge excel file with 210 columns from(A all the way to CK)-Each of these columns have 80000-300000 values.I want to read this into a MATLAB array.I have two problems:
1.Is there any way that I can loop through the letters iteratively(from A to CK)?
2.When I try to read the file as a whole it says no storage-but I am able to create a matrix of ones of size-300000*210....So Im a bit puzzled and dont know what to do..??
Thanks!!
Save in the .csv format from EXCEL, then use load -ascii in matlab.
You can loop through the Excel column with the option xlRange of xlsread (doc).
And both the output num = xlsread(...) and [num,txt,raw] = xlsread(...) duplicate the information being read in several variables (type edit xlsread in the command window).