How do I chart categorical, cumulative, and time-dependent data? - date

I have a bunch of time-dependent data, non-decreasing and right-continuous, always with come category involved, that can be repeated. I am looking for a sort of a variable width-bar chart, or cascade chart, flipped on it's side, from the right. For example,
set term postscript eps enhanced
set output "so.eps"
$Data <<EOD
# date source reg sic pic total
2000-07-25 2000glider C-FJSN 8 0 216
2000-07-28 2000glider C-FJSN 10 0 226
2000-07-28 2000glider C-FJSN 11 0 237
2000-07-28 2000glider C-GCLB 4 0 241
2000-07-29 2000glider C-GCLY 3 0 244
2000-07-29 2000glider C-GCLY 2 0 246
2000-07-29 2000glider C-GCLY 17 0 263
2000-07-30 2000glider C-GCLB 15 0 278
2000-07-30 2000glider C-GCLB 0 13 291
2000-07-30 2000glider C-GCLK 11 0 302
2000-07-30 2000glider C-FJSN 0 16 318
2000-07-30 2000glider C-GCLB 0 10 328
2000-08-02 2000glider C-GQRT 0 13 341
2000-08-04 2000glider C-GCLY 0 11 352
2000-08-05 2000glider C-GCLB 12 0 364
2000-08-05 2000glider C-GCLB 0 12 376
2000-08-06 2000glider C-GCLB 0 11 387
2000-08-07 2000glider C-GFMB 0 12 399
2000-08-07 2000glider C-GCMB 0 11 410
2000-08-08 2000glider C-GCLK 0 12 422
2000-08-09 2000glider C-GCLB 14 0 436
2000-08-09 2000glider C-GCLB 0 9 445
2000-08-10 2000glider C-GCLL 0 10 455
EOD
set monochrome
set xdata time
set timefmt "%Y-%m-%d"
set xtics format "%Y-%m-%d" rotate by -30
set ylabel "hours"
set grid
unset key
unset border
plot $Data using 1:($6/60) with fillsteps lw 2, \
$Data using 1:($6/60):3 with labels
Which gives,
I'm trying to create like a cumulative distribution function, where hours, in this case, are added. I want the line to go to zero on the left and the maximum value on the right. The labels, instead of printing, should be in the key and mapped to the data, grouped with other consecutive data, from the right. Is there such a plot, and how to I create it?
I have full control over the input, so I was thinking maybe an inverse-transform and rotate would be easier?

Not sure if I fully understood all your points correctly.
Maybe the following script might bring you closer to what you want.
Update:
If you want color bars for intervals then you could use the plotting style with boxxyerror (check help boxxy).
with boxxy requires either 4 or 6 columns. 4 columns would be (x):(y):(dx):(dy) for a box centered at x,y with +/-dx and +/-dy.
sum up your durations which are either in column 4 or 5 in the variable total. No need for column 6.
the difference dx=43200 (i.e. half a day in seconds)
There are different ways of plottings steps.
Script:
### cumulative plot with color code
reset session
$Data <<EOD
# date source reg sic pic total
2000-07-25 2000glider C-FJSN 8 0 216
2000-07-28 2000glider C-FJSN 10 0 226
2000-07-28 2000glider C-FJSN 11 0 237
2000-07-28 2000glider C-GCLB 4 0 241
2000-07-29 2000glider C-GCLY 3 0 244
2000-07-29 2000glider C-GCLY 2 0 246
2000-07-29 2000glider C-GCLY 17 0 263
2000-07-30 2000glider C-GCLB 15 0 278
2000-07-30 2000glider C-GCLB 0 13 291
2000-07-30 2000glider C-GCLK 11 0 302
2000-07-30 2000glider C-FJSN 0 16 318
2000-07-30 2000glider C-GCLB 0 10 328
2000-08-02 2000glider C-GQRT 0 13 341
2000-08-04 2000glider C-GCLY 0 11 352
2000-08-05 2000glider C-GCLB 12 0 364
2000-08-05 2000glider C-GCLB 0 12 376
2000-08-06 2000glider C-GCLB 0 11 387
2000-08-07 2000glider C-GFMB 0 12 399
2000-08-07 2000glider C-GCMB 0 11 410
2000-08-08 2000glider C-GCLK 0 12 422
2000-08-09 2000glider C-GCLB 14 0 436
2000-08-09 2000glider C-GCLB 0 9 445
2000-08-10 2000glider C-GCLL 0 10 455
EOD
# get a unique list from datablock
addToList(list,col) = list.( strstrt(list,'"'.strcol(col).'"') > 0 ? \
'' : ' "'.strcol(col).'"')
Uniqs = ''
stats $Data u (Uniqs=addToList(Uniqs,3)) nooutput
Uniq(i) = word(Uniqs,i)
getIndex(s) = sum [_i=1:words(Uniqs)] s eq word(Uniqs,_i) ? _i : 0
myTimeFmt = "%Y-%m-%d"
set format x myTimeFmt timedate
set xtics format myTimeFmt rotate by -30
set ylabel "hours"
set format y "%tH:%tM" timedate
set grid
set key out reverse Left noautotitle
set style fill solid 0.5
plot total=0 $Data u (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy) w steps lc "black" dt 3, \
total=0 '' u (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy,total-dy/2.): \
(43200):(dy/2.):(getIndex(strcol(3))) w boxxy lc var, \
for [i=1:words(Uniqs)] keyentry w boxxy lc i ti Uniq(i)
### end of script
Result:

Related

Unrecognized Quartz MS font

I tried to generate the image with the Quartz MS font as follows.
Then use jTessBoxEditorFX to generate the box file, as follows.
0 26 23 97 125 0
1 169 26 189 122 0
2 209 23 279 124 0
3 305 23 370 124 0
4 391 25 461 121 0
5 481 23 551 124 0
6 571 23 641 124 0
7 665 27 731 124 0
8 753 24 822 124 0
9 842 24 912 125 0
The traineddata cannot be recognized normally. Is there any problem with my practice?
Whether there are similar experiences of seniors can guide me, thank you.

Acrofields created with libre office are not code fillable unless I edit the pdf once

I am creating a form control in Libre office and am exporting the document to pdf.
Trying to set the text of the control (a textbox) using itextsharp (in other words c# program) only empties the box.
However, if I open the pdf using acrobat reader and edits the text in the box, saving the document results in a pdf where it is possible to write to that textbox.
Why do I have to do that?
Error reproduction
Cliking the toolbar icon in libre office.
Dragging out a square in the document.
Double clicking that box, giving it the name currenttime.
Exporting to pdf:
c# code
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (var fs = new FileStream(saveFileDialog1.FileName, FileMode.Create))
{
var reader = new PdfReader(openFileDialog1.FileName);
{
using (var pdfStamper = new PdfStamper(reader, fs))
{
var acroFields = pdfStamper.AcroFields;
acroFields.SetField("currentdate", DateTime.Now.ToString());
pdfStamper.FormFlattening = true;
pdfStamper.FreeTextFlattening = true;
pdfStamper.Writer.CloseStream = false;
}
}
reader.Close();
fs.Close();
}
}
}
edit
Here comes textual dumps of the pdf. I have changed some binary data places with "some binary data". The textbox has been given the default value "123".
pdf after it has been created with libre office is of version 1.4
%PDF-1.4
some binary data
2 0 obj
<</Length 3 0 R/Filter/FlateDecode>>
stream
some binary data
endstream
endobj
3 0 obj
78
endobj
7 0 obj
<</Type/FontDescriptor/FontName/LiberationSans
/Flags 4
/FontBBox[-543 -303 1301 980]/ItalicAngle 0
/Ascent 905
/Descent -211
/CapHeight 979
/StemV 80
>>
endobj
8 0 obj
<</Type/Font/Subtype/TrueType/BaseFont/LiberationSans
/Encoding/WinAnsiEncoding
/FirstChar 32 /LastChar 255
/Widths[277 277 354 556 556 889 666 190 333 333 389 583 277 333 277 277
556 556 556 556 556 556 556 556 556 556 277 277 583 583 583 556
1015 666 666 722 722 666 610 777 722 277 500 666 556 833 722 777
666 777 722 666 610 722 666 943 666 666 610 277 277 277 469 556
333 556 556 500 556 556 277 556 556 222 222 500 222 833 556 556
556 556 333 500 277 556 500 722 500 500 500 333 259 333 583 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
277 333 556 556 556 556 259 556 333 736 370 556 583 333 736 552
399 548 333 333 333 576 537 333 333 333 365 556 833 833 833 610
666 666 666 666 666 666 1000 722 666 666 666 666 277 277 277 277
722 722 777 777 777 777 777 583 777 722 722 722 722 666 666 610
556 556 556 556 556 556 889 500 556 556 556 556 277 277 277 277
556 556 556 556 556 556 556 548 610 556 556 556 556 500 556 500
]
/FontDescriptor 7 0 R>>
endobj
5 0 obj
<</F1 8 0 R
>>
endobj
9 0 obj
<</Font 5 0 R
/ProcSet[/PDF/Text]
>>
endobj
1 0 obj
<</Type/Page/Parent 6 0 R/Resources 9 0 R/MediaBox[0 0 595 842]/Annots[
4 0 R ]
/Group<</S/Transparency/CS/DeviceRGB/I true>>/Contents 2 0 R>>
endobj
6 0 obj
<</Type/Pages
/Resources 9 0 R
/MediaBox[ 0 0 595 842 ]
/Kids[ 1 0 R ]
/Count 1>>
endobj
10 0 obj
<</Type/XObject
/Subtype/Form
/BBox[0 0 82.7 23.1]
/Resources 9 0 R
/Length 18
/Filter/FlateDecode
>>
stream
some binary data
endstream
endobj
4 0 obj
<</Type/Annot/Subtype/Widget/F 4
/Rect[59.6 759.3 142.5 782.2]
/FT/Tx
/P 1 0 R
/T(currenttime)
/Ff 4096
/V <FEFF003100320033>
/DV <FEFF003100320033>
/DR<</Font 5 0 R>>
/DA(0 0 0 rg /F1 12 Tf)
/AP<<
/N 10 0 R
>>
>>
endobj
11 0 obj
<</Type/Catalog/Pages 6 0 R
/OpenAction[1 0 R /XYZ null null 0]
/Lang(sv-SE)
/AcroForm<</Fields[
4 0 R
]/DR 9 0 R/NeedAppearances true>>
>>
endobj
12 0 obj
<</Creator<FEFF005700720069007400650072>
/Producer<FEFF004C0069006200720065004F0066006600690063006500200035002E0033>
/CreationDate(D:20170606104859+02'00')>>
endobj
xref
0 13
0000000000 65535 f
0000001431 00000 n
0000000019 00000 n
0000000168 00000 n
0000001843 00000 n
0000001347 00000 n
0000001590 00000 n
0000000187 00000 n
0000000357 00000 n
0000001378 00000 n
0000001688 00000 n
0000002073 00000 n
0000002231 00000 n
trailer
<</Size 13/Root 11 0 R
/Info 12 0 R
/ID [ <5F5DD24A5E7FF740A8BB6B15F88EF602>
<5F5DD24A5E7FF740A8BB6B15F88EF602> ]
/DocChecksum /BFFAD3050AA9FF87945C97B9608B3C6C
>>
startxref
2406
%%EOF
after it has been edited in acrobat reader (I changed the default value of the textbox from "123" to "12"), it will be saved in version 1.6 and an interesting x:xmpmeta information is inserted. Also a lot of empty lines are inserted in the document. At this point, it is programmatically editable.
%PDF-1.6
%âãÏÓ
7 0 obj
<</Linearized 1/L 6449/O 9/E 2599/N 1/T 6160/H [ 451 149]>>
endobj
13 0 obj
<</DecodeParms<</Columns 4/Predictor 12>>/Filter/FlateDecode/ID[<5F5DD24A5E7FF740A8BB6B15F88EF602><FAE65369E246E7409111A7D5BDED1E6F>]/Index[7 17]/Info 6 0 R/Length 52/Prev 6161/Root 8 0 R/Size 24/Type/XRef/W[1 2 1]>>stream
some binary data
endstream
endobj
startxref
0
%%EOF
23 0 obj
<</Filter/FlateDecode/I 92/Length 65/S 38/V 69>>stream
some binary data
endstream
endobj
8 0 obj
<</AcroForm<</DA(/Helv 0 Tf 0 g )/DR 22 0 R/Fields[14 0 R]>>/Lang(sv-SE)/Metadata 1 0 R/OpenAction[9 0 R/XYZ null null 0]/Pages 5 0 R/Type/Catalog>>
endobj
9 0 obj
<</Annots[14 0 R]/Contents 12 0 R/CropBox[0 0 595 842]/Group<</CS/DeviceRGB/I true/S/Transparency>>/MediaBox[0 0 595 842]/Parent 5 0 R/Resources 22 0 R/Rotate 0/Type/Page>>
endobj
10 0 obj
<</BBox[0.0 0.0 82.9 22.9]/Filter/FlateDecode/Length 68/Resources 15 0 R>>stream
some binary data
endstream
endobj
11 0 obj
<</Filter/FlateDecode/First 66/Length 1226/N 9/Type/ObjStm>>stream
some binary data
endstream
endobj
12 0 obj
<</Filter/FlateDecode/Length 78>>stream
some binary data
endstream
endobj
1 0 obj
<</Length 3146/Subtype/XML/Type/Metadata>>stream
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.4-c005 78.147326, 2012/08/23-13:03:03 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<xmp:CreateDate>2017-06-06T10:48:59+02:00</xmp:CreateDate>
<xmp:CreatorTool>Writer</xmp:CreatorTool>
<xmp:ModifyDate>2017-06-06T11:20:41+02:00</xmp:ModifyDate>
<xmp:MetadataDate>2017-06-06T11:20:41+02:00</xmp:MetadataDate>
<pdf:Producer>LibreOffice 5.3</pdf:Producer>
<xmpMM:DocumentID>uuid:fcdf7344-18ca-44b6-934c-8d5ab8fc8ea3</xmpMM:DocumentID>
<xmpMM:InstanceID>uuid:895fdc09-0aaa-4421-86b2-418c75f88d22</xmpMM:InstanceID>
<dc:format>application/pdf</dc:format>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
endstream
endobj
2 0 obj
<</Filter/FlateDecode/First 4/Length 48/N 1/Type/ObjStm>>stream
some binary data
endstream
endobj
3 0 obj
<</Filter/FlateDecode/First 4/Length 106/N 1/Type/ObjStm>>stream
some binary data
endstream
endobj
4 0 obj
<</DecodeParms<</Columns 3/Predictor 12>>/Filter/FlateDecode/ID[<5F5DD24A5E7FF740A8BB6B15F88EF602><FAE65369E246E7409111A7D5BDED1E6F>]/Info 6 0 R/Length 37/Root 8 0 R/Size 7/Type/XRef/W[1 2 0]>>stream
some binary data
endstream
endobj
startxref
116
%%EOF
edit2
I was putting the files on my dropbox.
https://www.dropbox.com/sh/5btzl9qqzua18q1/AACIjCrvNZ5cunuLj9sze-l3a?dl=0
As already surmised in a comment, the problem is caused by Libre Office creating the PDF with NeedAppearances set to true in the AcroForm dictionary. Furthermore the wrong field name is used.
Field name
In your code you set the field "currentdate" while in your sample PDFs the field is called "currenttime". Obviously you have to use the correct field name.
NeedAppearances flag
This flag tells a PDF viewer that it shall construct appearance streams and appearance dictionaries for all widget annotations in the document. iText, therefore, when filling in the form field
acroFields.SetField("currentdate", DateTime.Now.ToString());
does not create an appearance for that field - any viewer is required to construct new appearances anyways.
Unfortunately form flattening
pdfStamper.FormFlattening = true;
is implemented by using the existing appearances and only them. As no appearance has been created when setting the field, its flattened form turns out to be empty.
(Strictly speaking this implementation of form flattening is wrong: In this case iText is the PDF processor that wants to make use of the appearances; thus, it should create all appearances here, even ignoring existing ones.)
You can fix this by telling iText to create appearances during form fill-ins in spite of the NeedAppearances flag:
using (var pdfStamper = new PdfStamper(reader, fs))
{
var acroFields = pdfStamper.AcroFields;
acroFields.GenerateAppearances = true;// <<<<<<<<<<<<<<<<<<
acroFields.SetField("currenttime", DateTime.Now.ToString());
pdfStamper.FormFlattening = true;
pdfStamper.FreeTextFlattening = true;
pdfStamper.Writer.CloseStream = false;
}
After adding the marked line above, the output of the code includes the changed newly set value.
Additionally Libre Office does not embed the LiberationSans font. As I have not installed it on my system, I only see dots. I would propose you make LibreOffice embed such fonts or else use standard 14 fonts. Otherwise your PDFs won't display as desired on a number of computers.

Triangular Multiplication Table

I'm working on a program that's supposed to write out the multiplication table as shown in the picture.
This is what I've done
A = (1:10)'*(1:10);
tril (A)
And this is my output. Is there a way I can do this without the zeros?
Or should I go with a different approach? Any help is greatly appreciated.
1 0 0 0 0 0 0 0 0 0
2 4 0 0 0 0 0 0 0 0
3 6 9 0 0 0 0 0 0 0
4 8 12 16 0 0 0 0 0 0
5 10 15 20 25 0 0 0 0 0
6 12 18 24 30 36 0 0 0 0
7 14 21 28 35 42 49 0 0 0
8 16 24 32 40 48 56 64 0 0
9 18 27 36 45 54 63 72 81 0
10 20 30 40 50 60 70 80 90 100
Here's one way:
A=tril((1:10)'*(1:10))
A(A==0)=NaN;
S=num2str(A);
S(S==78|S==97)=' '
The second line distinguishes plain old '0' from a pesky '0' in, say, '20'.
The third line converts the array to a string.
The last line replaces capital 'N' (character 78) and lowercase 'a' (character 97) with blank space.
Your approach is good, but if you want to avoid the zeros you want strings, not numbers. For example,
>> n = 10;
>> char(arrayfun(#(k) {sprintf('%i ', k:k:k^2)}, 1:n).')
ans =
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100
How it works
sprintf('%i ', k:k:k^2) generates each row of the table as a string. cellfun is used to iterate over all rows. The rows are packed into a cell array of strings, and that cell array is converted to a char matrix, which automatically pads with spaces.

Stacked-area with date format at x-axis on Gnuplot

I have created graphs using filledcurves. Now, the graphs looks bad because long range of data.
This is my data:
a b c d e f g h i
201312 49 26 34 30 14 25 9 4 1
201311 38 22 47 30 9 9 4 3 1
201310 44 24 43 38 9 14 5 7 0
201309 65 18 33 39 15 12 4 5 1
201308 42 31 44 30 5 11 0 2 2
201307 58 27 35 29 8 4 2 4 2
201306 30 22 15 17 2 6 3 4 0
201305 61 52 20 16 11 12 2 3 0
201304 62 60 33 18 13 9 5 6 0
201303 43 53 49 27 9 11 7 0 0
201302 31 30 42 27 10 8 4 2 0
201301 42 30 20 47 9 13 3 2 1
201212 26 19 39 24 9 11 0 0 0
201211 26 26 30 28 1 2 0 2 1
201210 55 46 34 30 13 5 0 2 1
201209 56 31 27 28 27 13 2 4 1
201208 48 75 38 46 22 10 0 1 0
201207 60 56 37 47 19 11 2 1 0
201206 60 41 37 28 17 12 5 1 0
201205 49 43 38 46 15 16 2 2 0
201204 43 50 36 33 4 7 3 0 2
201203 49 63 35 43 16 7 1 2 0
201202 43 59 59 52 16 13 3 4 1
201201 51 44 30 37 20 9 4 1 0
201112 50 38 36 36 8 2 3 1 1
201111 75 35 30 36 16 7 3 3 1
201110 68 53 41 27 11 15 1 2 1
201109 68 46 48 47 16 19 4 0 1
201108 45 41 20 36 17 10 1 0 0
201107 48 34 30 24 13 7 3 3 1
201106 49 29 24 25 5 6 0 3 0
201105 45 35 21 37 1 7 2 1 0
201104 53 35 23 18 4 6 1 5 1
201103 58 42 20 18 6 4 1 0 4
201102 54 32 19 20 4 10 0 2 0
201101 42 41 21 28 3 6 1 2 1
and this is my gnuplot file:
set terminal postscript eps color font 20
set xtics 1 out
set tics front
#set style fill transparent solid 0.5 noborder
set key below autotitle columnheader
set ylabel "Count"
set xlabel "across time"
set output 't1.eps'
set title "t1-Across time of Aspects"
set xtics 1
plot for [i=10:2:-1] \
"< awk 'NR==1 {print \"year\",$".(i-1)."} NR>=2 {for (i=2; i<=".i."; i++) \
{sum+= $i} {print $1, sum; sum=0} }' data.dat" \
using (column(2)):xtic(1) with filledcurves x1 t column(2)
When I add time in xdata:
set xdata time
set timefmt "%Y%m"
set xtics format "%b"
Erros message:
Need full using spec for x time data
Is the Errors because of my date format? I have googling this and do not have any answer about it. Please give me suggestion about this.
In the script you show, you specify only a single column in the using statement (besides the xtic). That means, that this value is taken as y-value and the row number is implicitely used as x-value.
When using time data, you must explicitely specify all columns which are needed for the plotting style, there is no assumption about what might be the first column. Use:
set key below autotitle columnheader
set ylabel "Count"
set xlabel "across time"
set tics front
set xdata time
set timefmt "%Y%m"
set xtics format "%b'%y"
set autoscale xfix
plot for [i=10:2:-1] \
"< awk 'NR==1 {print \"year\",$".(i-1)."} NR>=2 {for (i=2; i<=".i."; i++) \
{sum+= $i} {print $1, sum; sum=0} }' data.dat" \
using 1:2 with filledcurves x1 t column(2)
Result with 4.6.4:
I guess you don't want xtic(1) if you have time data and specify the x format.

Matlab: sum column elements with restrictions

We have a MxN matrix and a constrain cstrn = 100;.
The constrain is the summarize limit of column's elements (per column):
sum(matrix(:,:))<=cstrn.
For a given example as the following:
Columns 1 to 5:
15 18 -5 22 19
50 98 -15 39 -8
70 -15 80 45 38
31 52 9 80 72
-2 63 52 71 6
7 99 32 58 41
I want to find the max number of element per column who fulfill this constrain.
How can i summarize every column element with the others elements in same column and find which sum combinations uses the max number of elements per column?
In the given example solution is:
4 3 5 2 5
where
column 1: 15 + 50 + 31 +7 +(-2)
column 2: 18 +(-15) + 52 or 63 etc.
Thank you in advance.
Since it is always easier to fit small elements into a sum, you can do a sort, followed by the cumulative sum:
m= [
15 18 -5 22 19
50 98 -15 39 -8
70 -15 80 45 38
31 52 9 80 72
-2 63 52 71 6
7 99 32 58 41];
cs = cumsum(sort(m))
cs =
-2 -15 -15 22 -8
5 3 -20 61 -2
20 55 -11 106 17
51 118 21 164 55
101 216 73 235 96
171 315 153 315 168
Now you easily identify at which element you cross the threshold cnstrn (thanks, #sevenless)!
out = sum(cs <= cnstrn)
out =
4 3 5 2 5
I'd add to Jonas's answer, that you can impose your constraint in a way that outputs a logical matrix then sum over the 1's and 0's of that matrix like so:
cstrn = 100
m= [
15 18 -5 22 19
50 98 -15 39 -8
70 -15 80 45 38
31 52 9 80 72
-2 63 52 71 6
7 99 32 58 41];
val_matrix = cumsum(sort(m))
logical_matrix = val_matrix<=cstrn
output = sum(logical_matrix)
Giving output:
cstrn =
100
val_matrix =
-2 -15 -15 22 -8
5 3 -20 61 -2
20 55 -11 106 17
51 118 21 164 55
101 216 73 235 96
171 315 153 315 168
logical_matrix =
1 1 1 1 1
1 1 1 1 1
1 1 1 0 1
1 0 1 0 1
0 0 1 0 1
0 0 0 0 0
output =
4 3 5 2 5
Here is a logic, on mobile so can't give a code.
Check this out. Go to a column, sort it ascending order, loop to sum, break when hits <=100. Get counter. Refer back to original column, get the indices of elements matching the elements you just summed up :-)