In emacs, how to colorize a row in a CSV based on value in a column? - emacs

I have created a major-mode for emacs that I use for data analysis. This mode works great for me but it's drab and I don't take advantage of color the way I should. The data being analyzed is in a CSV format and I'd like to colorize the rows within based on values in the columns.
Let's say I have the following file in CSV format:
one,1,2,3
two,4,5,6
three,7,8,9
The rows in this CSV should be colored with red based on the value in the 4th column and the intensity of the red should increase with that same value. So in this case the last column should be the most intense red and the first should be the least red.
I've read over Search Based Fontification and I'm a bit confused as to how I would write a (matcher . facespec) that sets the facespec properly. facespec is an expression that evaluates to
(face face prop1 val1 prop2 val2…)
but how do I make this depend on the values in the fourth column of my CSV? I guess the value in the fourth column is what gets matched but how do I tie the face used to the magnitude of the value matched? I suppose I need to generate a face on the fly based on the value matched but not sure how to do so.
Any ideas? A simple example would be best.

Related

Conditional Formatting: Highlight cells of a range if cell equal to any values of an array

I would like to streamline the visualization of scales in the guitar fretboard.
However, I can't overcome the current problem
From the range B3:S8 (the entire fretboard) I would like to highlight the cells which match with the values of the range W3:W9 (the C major scale)
I've found some intermediate solutions, where I would need to repeat it for each line of the range of the fret.
Seeking now a way where the whole fret range would match an one dimension array of values.

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")

printmat function: Decimal and percentage

I am very new to MATLAB. I am sorry if my question is basic. I am using "printmat" function to show some matrices in the command console. For example, printmat(A) and printmat(B), where A = 2.79 and B = 0.45e-7 is a scalar (for the sake of simplicity).
How do I increase the precision arbitrarily to seven decimals? For example: my output looks like 2.7943234 and B = 0.00000004563432.
How do I add a currency (say dollar) figure to the output of printmat?
How do I add a percentage figure (%) to the output of printmat?
Note: The reason I use printmat is that I can name my rows and columns. If you know a better function that can do all above, I would be glad to know.
Regards Mariam. From what I understand, you would like to display the numbers and show their full precision. I am also newbie, If I may contribute, you could convert the number data to string data (for display purposes) by using the sprintf function.
I am using the variable A=2.7943234 as example. This value will not display the full precision, instead it will display 2.7943. To show all the decimal tails, you could first convert this to string by
a = sprintf('%0.8f',A);
It will set the value a to a string '2.79432340'. The %0.8f means you want it to display 8 decimal tails. For this example,%0.7f is sufficient of course.
Another example: A=0.00000004563432, use %0.14f.
A=0.00000004563432;
a=sprintf('%0.14f $ or %%',A);
the output should be : '0.00000004563432 $ or %'.
You could analyze further in https://www.mathworks.com/help/matlab/ref/sprintf.html
You could try this first. If this does not help to reach your objective, I appreciate some inputs. Thanks.
The printmat function is very obsolete now. I think table objects are its intended successor (and functions such as array2table to convert a matrix to a table of data). Tables allow you to add row and column names and format the columns in different ways. I don't think there's a way to add $ or % to each number, but you can specify the units of each column.
In general, you can also format the display precision using format. Something like this may be what you want:
format long

How to show fuzzy output result in label not in interger value?

I work on fuzzy in MATLAB and I make some rules with two shape features input (edge pixel count and minimum X axis). and use mamdani algorithm, and also define an output (my output has 4 trimf with separate labels). I export my fuzzy to my workspace and save it with DotFuzzy name.
I write DotFuzzy(23,29); to call my fuzzy set and wait for result. but show me error.
>> DotFuzzy(23,29)
Index exceeds matrix dimensions.
then I wrote this:
evalfis([23,29],DotFuzzy)
ans =
0.2500
But I think it shows me the result that this number is contain. ( for example show the trim label instead of this number)
How can I show the result in class label not in number value?
I find the reason. Fuzzy can not show the result in class label. It just show the output in numbers. But we can define the interval for each label in output and get the last result number and check it between the interval. For example if the result is 0.42 and in output this number belong to class label B (with this interval 0.30-0.50) so make structures and check the interval in your code and print B in output.

Display multiple values in one line

I'm new to MATLAB. I have two values x and y. Both of them contain values with unknown accuracy. The problem: How could I display them both in one row with 2 digits after comma? Like:
x<tabulation or stack of spaces>y<then goes new line>
Example
RAW data
0,324352 0,75234
1,563 3,4556
Expected output
0,34 0,75
1,56 3,45
Upd: for one value it works well
disp('x=' num2str(x,3));
Purpose is: display TWO values on one row with the new line symbol
The answer is:
disp(num2str([x y],3));
The 3 value means - max.quanity of symbols after comma including it(am I wrong? just thoughts)
Another Idea:
Somehow represent X and Y as array values and then display them.