In matlab one of my variable produce a sort of number as follows:
t =
1.0e-07 *
Columns 1 through 4
0.000002188044002 0.000011853757224 0.000043123777130 0.000134856642090
Columns 5 through 8
0.000414700915105 0.001479279377534 0.003134050793671 0.008617995925603
Columns 9 through 12
0.065830078792745 0.087987267599604 0.106338163623915 0.121617374878836
Columns 13 through 16
0.134520178924611 0.145518794399287 0.155035638788571 0.163042823513867
Columns 17 through 18
0.170181805020581 0.172442168463983
How I can produce them in one column in order to easily copy and paste to Excel?
try
format long g
t'
or else just double click on t in your workspace and you'll get a datagrid (the variable editor) that you can just copy and paste out of
Try using this:
fprintf ('%g\n', t);
Which won't have the leading spaces you get from format long g; t'
Related
I have a series of values such as:
10RP
2.5R
5R
7.5R
10R
2.5YR
5YR
I want to convert the string portion to a number based on this table:
0 R
10 YR
20 Y
30 GY
40 G
50 BG
60 B
70 PB
80 P
90 RP
I then want to create two columns so that:
2.5YR
becomes:
2.5 10
In a third column I will add the two numbers together.
Can this be done just using formulas? I want to avoid using VBA if I can.
Thanks.
Here's another approach.
seq is a defined name referring to an array constant ={1,2,3,4,5}
If you might have numbers that encompass more than five characters, just extend the constant appropriately.
Number part: =LOOKUP(9E+307,--MID(A1,1,seq))
Letter portion converted to number:
=VLOOKUP(MID(A1,LOOKUP(2,1/ISNUMBER(-MID(A1,1,seq)),seq)+1,9),$F$1:$G$10,2,FALSE)
Where your table is in F1:G10 and reversed so that the letters are in the first column
This might not be the most efficient but should work
=IFERROR((LEFT(F3,LEN(F3)-2)+VLOOKUP(RIGHT(F3,2),$A$3:$B$12,2,0)),
(LEFT(F3,LEN(F3)-1)+VLOOKUP(RIGHT(F3,1),$A$3:$B$12,2,0)))
Where your lookup table is A3:B12 with the letters in the left-most column
Check for the two-letter combinations before the single-letter ones.
I'm trying to do a match-and-calculate formula in Excel (or in Numbers for Mac, is the same for me: I try them both as they seem equal, also function names are equal!).
This is what I have:
| 1 | 2 | 3 |
|-----------+-----------+-----------|
| Category |other stuff| duration |
|-----------+-----------+-----------|
| A + .... ... + 00:01:23 |
|-----------+-----------+-----------|
| A + .... ... + 00:30:19 |
|-----------+-----------+-----------|
| B + ......... + ......... |
|-----------+-----------+-----------|
| A + .... ... + 00:22:12 |
... ... ....
So, in column 3 I have a duration in time in this format "hh:mm:ss" and in column 1 are stored all of my categories.
I want to search for all rows in my table that are matching with the category "A" in column 1 and take the relative column 3, splitting the string and converting chars to numbers (in particular I'm interested in converting them to secs, so hh*3600+mm*60+ss) and finally sum up all these values. Is it possible?
I'm new with Excel and Numbers, but I'm pretty familiar with coding in programming languages generally: this is what I'd do in programming:
global_secs=0;
for(row r=top to end){
if(r.get_column(1).content_equals("A")){
cell c=r.get_column(3);
string=split(c.get_content(),":")
global_secs+=int(string[1])*3600+int(string[2])*60+int(string[3])
}
}
Is there a way to achieve this in Excel sheet (or Numbers)?
I'd like to do all of this in one, or more, formula only in Excel or Numbers.
One more thing: I do not want to change cells format because this should be an automatic process without human interaction, so unless there is a function to change a range of cells format dynamically I prefer not to do that (I know I can make "duration" as format and sum up without converting to integer, but originally my data is in hh:mm:ss format)
Thanks so much!
The formula you are looking for is
=SUMIF(A2:A5,"A",C2:C5)
The easiest way to get the result in seconds would have been to format the cell as [ss] in Custom category. But as you don't want to do formatting , the other way could be
=HOUR(result) * 3600 + MINUTE(result) * 60 + SECOND(result)
So formula becomes
=HOUR(SUMIF(A2:A5,"A",C2:C5)) * 3600 + MINUTE(SUMIF(A2:A5,"A",C2:C5)) * 60 + SECOND(SUMIF(A2:A5,"A",C2:C5))
See image for referecne
Looks like a matrix formula
=SUM(N($A$2:$A$8="A")*$B$2:$B$8)
where column A contains the category and column C the duration. Note you need to press ctrl shift enter to make it work.
To convert the result to seconds, an alternative approach to #Mrig' solution would be to format the result and convert it back to a number, i.e.
=VALUE(TEXT(SUM(N($A$2:$A$8="A")*$B$2:$B$8),"[ss]"))
I have a Matlab script with an output of a multidimensional array LCOE (3 dimensions) of size 16:12:34. This output needs to be written to Excel, therefore I use xlswrite.
I have tried this:
T = LCOE(:,:,1);
xlswrite('filename', T, 'sheetname', 'B2');
This does what it's supposed to, but only writes one table to excel, and I would like to write all 34 tables to excel underneath each other, spaced by `2 blank rows.
Then, I tried this:
for y = 1:34
T = LCOE(:,:,y)
xlswrite('filename', T, 'sheetname', strcat('B', num2str(2+(y-1)*18)));
This works, but is very slow, since matlab writes each table separately to excel. Is there a faster way to do this?
Instead of using xlswrite again and again. Dump all the values of a 3D matrix into a 2D matrix and add rows of NaNs so that when you write that to excel file, you get 2 blank rows.
Following code improves the execution time by the factor of more than 10.
LCOE = 100*rand(16,12,34); % Taking random values for LCOE
T = NaN(18*34-2 ,12); % 1. Pre-allocation 2. 16+2 = 18
% Following loop dumps all the values of 3D matrix into a 2-D followed by 2 rows of NaN
% to leave 2 blank rows in excel file.
for k = 1:34
T(18*(k-1)+[1:16], :) = LCOE(:,:,k);
end
xlswrite('filename', T, 'sheetname', 'B2'); % Writing the Excel file
In my system, my code takes about 1 second to execute while your code takes about 10.5 seconds. So that's a significant difference.
After scraping a website I ended up with values with dashes in the data like 7-6, 12-5, 3-12. I was able to separate the data into to their own columns making the previous examples being 7, 6 , 12,5 3,12, but the data has turned from values that you can add and subtract to something like a string. Is there a way to make the strings into values.
0 15
1 2
5 6
4 8
3 2
2 1
If i go through each cell and double click the strings it converts to values, but I cant do that to 55000 cells.
you can convert a text string that represents a number to number format using the Value() formula
Example:
B1 = Value(A1))
if A1 = 15 in text format
You can select the whole columns and convert to number. Go to menu Data > Convert and then, follow the wizard.
I have a number of dates in an Excel file associated with some other numbers, then I want to import this data in Matlab.
E.g. I have 5/17/06 on Excel and in Matlab it appears as 0.0490196078431373
when I try to import it..
How can I import the dates correctly into matlab??
Thank you in advance!
Here is an idea of what you need to do.
[A B C] = xlsread('C:\Users\Admin\Desktop\test.xlsx') %This is just a dummy file I made to test with.
B will contain the data from the excel file. It is VERY important to note that it will be the exact same as the layout from excel. This is what I have in the dummy file:
5/17/06 asd 12
5/18/06 s sd
5/19/06 asd asd
5/20/06 dsd sd
5/21/06 e2 asd
So the resulting matrix B will be a cell array with 3 columns and 5 rows. You can then pull the date out into a separate matrix like so:
date = B(:,1)
Now date is a vector of cells that contain the dates you had before. You can then apply other functions to convert to a char array (string) if you want to, etc.