how to get sum of consecutive number by selecting them with mouse courser - select

I'm trying to write a code for getting a sum of consecutive numbers.
for example:
if we have these numbers in a list:
2,4,5,6,7
I want a code that enables me to select a specific number in the list by mouse courser (very important), for example, 5 and 6 and it finally gives me the sum.
thanks,

Related

Look up an account then average associated values excluding zeros

On one sheet, I have account code and in the cell next to it, I need to look up the account code on the next sheet to average the cost excluding those cells that are zero in col. b from the average calculation.
The answer for London should be: £496.33 but having tried various sumifs / countifs I cannot get it to work.
You probably need COUNTIFS which -- similar to the SUMIFS you are already using -- allows to define multiple critera and ranges.
So, if the column R contains the values, you want to build the average upon, and the column H in the respective row must equal $B$28 to be included in the sum, the respective COUNTIFS looks as follows
=SUMIFS('ESL Info'!$R:$R,'ESL Info'!H:H,$B$28)/COUNTIFS('ESL Info'!$H:$H,$B$28, 'ESL Info'!$R:$R, "<>0")
ie additionally to the value in the H-column to equal B28 it also requires the value R-column (ie the actual number you are summing up) to be different from 0
You could also add the same criteria 'ESL Info'!$R:$R, "<>0" to your SUMIFS, but that isn't necessary, because a 0 doesn't provide anything to you sum, thus it doesn't matter if it's included in the sum or not ...
And depending on the Excel version you are using, you may even have the AVERAGEIFS function available, which does exactly what you want
=AVERAGEIFS('ESL Info'!$R:$R,'ESL Info'!$H:$H;$B$28,'ESL Info'!$R:$R,"<>0")

How do I display all perfect squares below a given number on scratch?

I was able to list all the prime numbers up to an inputted number, however as I am inexperienced at coding on Scratch, I have had difficulty constructing a list of all the perfect squares below a number.
For example, if you input 17 the output should be 16,9,4.
The main way to detect if a number is a perfect square is to take the square root and round it and then multiply it by itself. If it is a perfect square the answer will be the number you started with.
Let's try with 4: The square root of 4 is 2 and when you round it you get 2 and when you multiply 2 times 2 you do get 4 so 4 is a perfect number.
Let's try with 5: The square root of 5 is 2.23606797749979 and when you round it you get 2 and when you multiply 2 times 2 you do NOT get 5.
There are two ways to write the loop: you can count up or you can count down. Either way, for each number you do the test and if the number is a perfect square you display it.
counting down:
counting up:

Counting and finding sum of combination of Dimensional attributes

Got a field in Excel:
Treament Status
IT
IT
SD
USD
SD
SD
USD
I need to use a calculated field to find a Percentage of total using this mathematical formula, based on the number of times certain dimensional attributes appears in the column i.e. Count:
% of R = [Count(SD)+Count(IT)]/[Count(Total of everything in Treatment Status)]
I know how to use the COUNT and SUM functions but I'm trying to connect the dots here.
One simple approach without writing any calculations is
Put Treatment Status on the Row shelf (double click should do it)
Number of Records on the Text Shelf (double click on it for a shortcut)
Then right click on the Number of Records field on the marks card and select Quick Table Calc -> Percent of Total
If you want to combine the SD and IT rows, select both SD and IT, then use the paperclip icon to group them together
The effect is to generate a query like select count(1) from xxx group by TreatmentStatus, and then to compute the percentages in Tableau acting upon the query results.
You need the TOTAL function. This should do it.
% of R = [Count(SD)+Count(IT)]/TOTAL(COUNT([Treatment Status]))

How do I find frequency of values appearing in all rows of a matrix in MATLAB?

I have a 161*32 matrix (labelled "indpic") in MATLAB and I'm trying to find the frequency of a given number appearing in a row. So I think that I need to analyse each row separately for each value, but I'm incredibly unsure about how to go about this (I'm only new to MATLAB). This also means I'm incredibly useless with loops and whatnot as well.
Any help would be greatly appreciated!
If you want to count the number of times a specific number appears in each row, you can do this:
sum(indpic == val, 2)
where indpic is your matrix (e.g image) and val is the desired value to be counted.
Explanation: checking equality of each element with the value produces a boolean matrix with "1"s at the locations of the counted value. Summing each row (i.e summing along the 2nd dimension results in the desired column vector, where each element being equal to the number of times val is repeated in the corresponding row).
If you want to count how many times each value is repeated in your image, this is called a histogram, and you can use the histc command to achieve that. For example:
histc(indpic, 1:256)
counts how many times each value from 1 to 256 appears in image indpic.
Like this,
sum(indpic(rownum,:) == 7)
obviously change 7 to whatever.
You can just write
length(find(indpic(row_num,:)==some_value))
and it will give you the number of elements equal to "some_value" in the "row_num"th row in matrix "indpic"

Extract a specific row from a combination matrix

Suppose I have 121 elements and want to get all combinations of 4 elements taken at a time, i.e. 121c4.
Since combnk(1:121, 4) takes a lot of time, I want to go for 2% of that combination by providing:
z = 1:50:length(121c4(:, 1))
For example: 1st row, 5th row, 100th row and so on, up to 121c4, picking only those rows from a 121c4 matrix without generating the complete combination (it's consuming too much for large numbers like 625c4).
If you haven't defined an ordering on the combinations, why not just use
randi(121,p,4)
where p is the number of combinations you want in your set ? With this approach you may, or may not, want to replace duplicates.
If you have defined an ordering on the combinations, tell us what it is.