Reading from an Excel File and manipulating Data - excel

I'm using Matlab to read from an Excel file. I'm supposed to be reading a column of integers called Change Due. After I read the column I am supposed to be calculating the change,in Quarters,Dimes..etc
I can read the column no problem,and I understand the math of how to calculate the change. however using a condition to check the amount of change is difficult...
Problem:
I know that for Multiplication/Division of Vectors you can add a period to make it a scalar .* or ./
But how do I parse through a vector with a condition?
if(Change.<25&&Change.>=10)
I get this Error:
Operands to the || and && operators must be convertible to logical scalar values.
If I was to just simple leave the period out I would not get an error message but it only goes through the first row for calculations.
Code:
% Filename: Program_04_1
% Author: Stewart Moon
% Assisted by: No one
% Program Description:
% The purpose of this program is to demonstrate how to read from an Excel
% file and to then calculate the amount of coins it will take per row
clc % clc clears the contents of the command window
clear % clear, clears all defined variables form the Matlab workspace
close all % closes all figure windows
% Declare Variables
Quarters=0;
Dimes=0;
Nickels=0;
Pennies=0;
TotalCoins=0;
% Output of the title and author to the command window
fprintf('Output for Program_04_1 written by Stewart Moon.\n')
fprintf('\nOriginal Data read from Program_04_1_Data.xlsx\n')
fprintf('\nMinimum Number of Coins Needed to Make Change\n')
Change=xlsread('Tutorial_04_1_Data.xlsx','Coins','B4:B43'); % Reading the column in Excel and storing it the variable Change
% Output Header Format
fprintf('\nChangeDue(cents) Quarters Dimes Nickels Pennies Total Coins\n\n')
table=[Change];
disp([table])
Command Window Output:
Output for Program_04_1 written by Stewart Moon.
Original Data read from Program_04_1_Data.xlsx
Minimum Number of Coins Needed to Make Change
ChangeDue(cents) Quarters Dimes Nickels Pennies Total Coins
1
4
5
6
10
14
15
16
20
24
25
29
30
31
35
37
40
42
45
49
50
54
55
56
60
64
65
68
70
73
75
77
80
81
85
88
90
91
95
99
Calculating Change Pseudo Code:
while(Change>0)
if (Change>=25)
Change=Change-25;
TotalCoins=TotalCoins+1;
Quarters=Quarters+1;
end
if (Change<25&&Change>=10)
Change=Change-10;
TotalCoins=TotalCoins+1;
Dimes=Dimes+1;
end
if (Change<10&&Change>=5)
Change=Change-5;
TotalCoins=TotalCoins+1;
Nickels=Nickels+1;
end
if (Change<5&&Change>=1)
Change=Change-1;
TotalCoins=TotalCoins+1;
Pennies=Pennies+1;
end
end

From my understanding, you want to achieve something like:
for i = 1 : length(Change)
% your conditions using indices for the array
% example:
% if(Change(i) > 25)
% instructions
% end
end

Related

excel incrementation by consecutive numbers

I have a form, thanks to user JamTay317, That lists data depending on folder number (bold number in form). I need to copy it for all 1500 folders (about 400 pages)
Form is divided on 4 labels on a page for easier printing
form overview
Form get it's folder number (nr teczki) from list with all folders from another sheet called "lista teczek":
list of folders
For first 4 folder numbers I use formula:
A2='lista teczek'!A1
J2='lista teczek'!A2
A21='lista teczek'!A3
J21='lista teczek'!A4
When I copy whole page underneath it increments by 36 (number of rows between)
A38='lista teczek'!A37
J38='lista teczek'!A38
A57='lista teczek'!A39
J38='lista teczek'!A40
Instead of A5, A6, etc.
Is there any way to override excel's incrementation to force it to use consecutive numbers? Or at least formula which will make it easier to follow folders list?
So I would use offset() to get the correct position
=A2=OFFSET('lista teczek'!$A$1;ROW(A1)-INT(ROW(A1)/36)*36+4*INT(ROW(A1)/36)-1;0)
So this will offset from A1 in the list sheet.
Below are row numbers a resultant lookup row numbers
Note the formula I used in the offset has an extra "-1" as this is an OFFSET so to get 1 from 1 we need to offset by 0
1 1
2 2
3 3
4 4
37 5
38 6
39 7
40 8
73 9
74 10
75 11
76 12
109 13
110 14
111 15
112 16
145 17
146 18
147 19
----LOGIC--- (edit)
So the idea is that you work out the occurrence you are on. Int(row()/36) gives us this. For example
int(1/36)=0
Int(363/36)=10
First part gives us the offset from the start of the occurrence
3-int(3/36)*36=3
378-Int(363/36)*36=3
Second part give the total of the previous occurrence
4*int(3/36)=0
4*Int(363/36)*36=40
So you need to change the 36 to the gap between the occurrences and the 4 to the length of occurrences Not sure if that helps to explain

PowerPivot: How to identify Max Value per Group in a Calculated Column

I am building a data model within Power Pivot for Excel 2013 and need to be able to identify the max value within a column for a particular group. Unfortunately what I thought would work and what I have searched for previously gave me an error or wasn't applicable (there was a similar question that dealt with calculated measures rather than columns and wasn't replicable in Power Pivot data view to the best of my knowledge)
I have included an indication of what I am trying to achieve below, in this case I am trying to calculate the Max % uptake column.
Group | % uptake | Max % uptake
A 40 45
A 22 45
A 45 45
B 12 33
B 18 33
B 33 33
C 3 16
C 16 16
C 9 16
Many thanks
Use
=CALCULATE(MAX([UPTAKE]),FILTER(Table1,[GROUP]=EARLIER([GROUP])))
use this formula in cell ("C2"):
=MAX(INDIRECT(CONCATENATE("B",MATCH(A2,$A$1:$A$10,0),":B",SUMPRODUCT(MAX(($A$1:$A$10=A2)*(ROW($A$1:$A$10)))))))

Time Lookback Calculation

I have two columns:
Column A: Time (seconds from midnight)
Column B: Value (arbitrary value I've created)
How would I find the average value (column B) at any instance in time(row) looking back over the previous x seconds (column A)?
Lets assume A1 = Seconds after midnight
Seconds after midnight Value
0 27
2 29
6 2
16 29
20 19
24 4
34 2
40 1
44 4
54 12
64 12
71 3
81 30
91 21
92 1
93 27
97 12
104 30
112 25
Note that time deltas are variable so I can't just look at the last x rows.
A specific question would be:
In a new column (column C) return the average Value of the last 10 seconds of data.
I have no idea how to do this. Can anyone help? It'd be greatly appreciated.
EDIT:
The output in the first 4 rows of column C would be:
Seconds after midnight Value Result
0 27 No values prior to this one
2 29 27 Average(B2)
6 2 28 Average(B2:B3)
16 29 2 Average(B4)
For each row, I'm taking the current time (16 in the last case)...going back x seconds (10 seconds in this case) and then averaging the values from all the cells in that time range (not including the current value).
My main issue is the time calculation. I don't know how to calculate it as I roll forward in time and I continue to get more instances as we move forward. If we go 10 seconds without any new data point then there would be no output since. If we got one instance in the previous 10 seconds then the output would be that value. If we got 100 instances in the previous 10 seconds, I need to return the average of that 100 instances.
Again, I'd appreciate any help, hints, links. This is driving me crazy.
Try the following formula in cell C3:
=IFERROR(SUMIFS(B:B,A:A,"<"&A3,A:A,">="&A3-10)/COUNTIFS(A:A,"<"&A3,A:A,">="&A3-10),0)
SUMIFS will get the sum of all values for which the seconds are:
less than A3 (i.e. less than 2 in this case)
more or equal to A3-10 (i.e. above -8 in this case)
And this sum is divided by the number of lines found with the same criteria.
If now there is an error (more specifically when the COUNTIFS returns 0, you would get #DIV/0!) you simply get 0 instead of the error.

Excel nesting error

I'm using Excel 2013 and I have had to create a If statement which basically chooses a student's grade depending on a certain mark number (obviously, nesting is needed) Here is the If statement I created:
=IF(E2<=20,"N",
IF(OR(E2>=21,E2<=25),4,
IF(OR(E2>=26,E2<=32),"5C",
IF(OR(E2>=33,E2<=38),"5B",
IF(OR(E2>=39, E2<=44), "5A",
IF(OR(E2>=45, E2<=53), "6C",
IF(OR(E2>=54, E2<=61), "6B",
IF(OR(E2>=62, E2<=71), "6A",
IF(OR(E2>=72, E2<=87), "7C",
IF(OR(E2>=88, E2<=103), "7B",
IF(OR(E2>=104, E2<=120), "7A")))))))))))
The error I receive is:
the specified formula cannot be entered because it uses more levels of nesting than allowed in the current file format
My question is, how do I shorten this statement to allow Excel to use it?
Place the logic in the spreadsheet cells. One column for the minimum score, and one column for the grade-:
A B
1 0 N
2 21 4
3 26 5C
4 33 5B
5 39 5A
6 45 6C
7 54 6B
8 72 7C
9 88 7B
10 104 7A
Then do a vlookup to get the grade from the actual score. vlookup will find the highest value in the A column that is less that the lookup value of 38.
In the example vlookup below 38 is the score, A1:B10 is the lookup table 2 is the 2nd column (in this case the B column) that contains the result (the grade).
=VLOOKUP(38, A1:B3, 2, TRUE)
You can also use the following formula.
=LOOKUP(E2;{0;21;26;33;39;45;54;62;72;88;104;121};{"N";4;"5C";"5B";"5A";"6C";"6B";"6A";"7C";"7B";"7C";"No match"})
There are a few different solutions. AND agreements using OR instead of the first that comes to mind.
=IF(E2<=20,"N",
IF(AND(E2>=21,E2<=25),4,
IF(AND(E2>=26,E2<=32),"5C", ...
The best way, in my opinion, is to write a UDF. Then you can use VBA and a CASE statement.
Experiment with this code in VBA to create a UDF named GRADE() - just type it into a MODULE in the VBE:
Function Grade(Marks)
Dim Score As Integer
Score = Marks * 1
Select Case Score
Case 1 To 20
Grade = "N"
Case 21 To 50
Grade = "C"
Case 51 To 90
Grade = "B"
Case 91 To 120
Grade = "A"
End Select
End Function
Then use the Function GRADE() as you would any other function but type the address of the argument - like this GRADE(B7) to use it
=+IF(O3="Negative","Negative",IF(P3="Negative","Negative",IF(Q3="Negative","Negative",IF(R3="Negative","Negative",IF(O3="Refer","Refer",IF(P3="Refer","Refer",IF(Q3="Refer","Refer",IF(R3="Refer","Refer","Positive"))))))))
I find the final status in 4 cells have positive,negative,refer,pending or blank

Find what range a number belongs to

Ive written a function to calculate what MARK a student gets, based on a scoring table.
Why does my function work only for A mark?
This what the excel sheet looks like
COLUMN: A B C
Student SCORE MARK
1 adsf 90 A
2 asgfd 89 FALSE
3 A 90 100
4 B 81 89
5 C 71 80
6 D 61 70
7 E 56 60
8 Fx 0 55
This is the function:
{=IF(B1>=$B$3:$B$8,IF(B1<=$C$3:$C$8,$A$3:$A$8))}
I'm using {} brackets for array functions. (CTRL SHIFT ENTER)
Thank you
You're on the right track but your formula is returning an array not a single value. Wrapping the result in LOOKUP should give the desired result:
=LOOKUP("Z",IF(B1>=$B$3:$B$8,IF(B1<=$C$3:$C$8,$A$3:$A$8))
This returns the last matching grade since "Z" is larger than any other text value in the range.
A simpler method is:
=LOOKUP(-B1,-C$3:C$8,A$3:A$8)
The negative signs are needed so that the lookup values are in ascending order.

Resources