Cannot plot in Matlab. It says my matrix is empty. Weird? - arrays

Doing some simple plotting and I cannot seem to figure out why I can't plot my data. I troubleshooted it first by checking to see if I had any data in my arrays first. I did not!! I'm completely lost on how to fix this.
I also tried creating a script to see if maybe it solved the issue instead of using the command window. I still get the same error.
Code:
t=0:1e-6:((2e-3-1e-6)-1);
vm=sin(2*pi*1e3*t);
vc=sin(2*pi*20e3*t);
vdsb=vc.*vm;
plot(t,vdsb,'b')

You probably don't want that last -1 in your code setting up t. Try changing t to:
t=0:1e-6:((2e-3-1e-6));
Or, if you really want it negative, you need to change the step size to negative:
t=0:-1e-6:((2e-3-1e-6)-1);
Otherwise, t is defined from 0:psotiveStep:negativeNumber and so it is empty.

Related

Why gdal.open(path).ReadAsArray() produce different results from tiffile.imread(path)

Since colab won't allow me to use tiffile.imread() by giving error 'ValueError: <COMPRESSION.LZW: 5> requires the 'imagecodecs' package', I use gdal.open().ReadAsArray() to read tif file and generate input data for model to inference. This results in:
When I use tiffile.imread() to read the same tif.file in another platform and created input with the same procedures as above. The model prediction finally goes to:
The results from the second image makes sense for the classes I want to predict. I just want to the reason that caused this difference. It seems gdal changed the order of pixels?
This finally works for me. Since I cannot use tiffile.imread() in colab, I tried gdal and rasterio, but the image shape would be channel first. The problem for the first figure is caused by
np.reshape()
which did not change the axis of data dimension.
Then I used codes below and the issue is addressed.
with rio.open("gdrive/My Drive/file.tif") as ds:
arr=ds.read()
np.moveaxis(arr, 0, -1)

Is there a way to sort a no. of character arrays in alphabetical order without using the #include<string.h> or #include<stdlib.h>?

So, I have tried to do the same in a case of array of structures where 'char name[100]' is the only data member.
1st part of the code
2nd part of the code
The problem that I have encountered here is that once I provide a no. of names during program runtime, the output screen either does not print anything afterwards, or, prints the data without sorting it.
output screen
I did not get any compile time errors so I believe that there is a flaw in the logic.
There's this another method I tried hoping to get positive results. I type-casted characters to integers hoping that ASCII values could be used to compare. But, the results are exactly the same (undesired results).
updated logic of the 2nd part of the code
I hope somebody helps me find a way to correct this logic or provide another logic that is efficient.
the sorting logic you used is good , but from what is see the use of function's in C need's to be provided by pointers. other wise all the data inside the function will born and die inside the function , and the all the variables in the Main will stay the same as given, that explains why the output is the same as the input
try to print inside the sorting function's to see if this is the problem.

calculate char's bbox with mupdf fz_stext_char_bbox

I occur an strange phenomenon using mupdf, which when I use fz_stext_char_bbox to get char's bbox, a lot of bbox are correct, but a little are wrong. I draw the bbox with red rectange on screen. Following picture is my capture:
these wrong bbox are always 0 on lefttop. In my code,
I get the fz_page by pageNo first.
then I use fz_new_stext_sheet, fz_new_stext_page and fz_new_stext_device create necessary parameter.
I use fz_run_page with current matrix and above parameters.
then I following the mupdf to use fz_stext_char_bbox in order to get the bbox.
I'm not sure it's necessory to list my code here, becaause it maybe too long. I seems my transform matrix is right but don't know why has wrong bbox. Do I forget something?

Error in google spreadsheet with arrays

In google spreadsheet I receive an error and it says, "Array result was not expanded because it would overwrite data in M261". I looked in M261 and it is a blank cell, but the weird thing is if I hit the delete button on the empty cell, then the error goes away. Sadly it keeps coming back. Is there a fix for this?
Here is my formula:
=ARRAYFORMULA(IF(E2:E>0,IF(D2:D=0,"Need Due Date",""),""))
I did not see "Array result was not expanded because it would overwrite data in M261" but at one point did see "...Add more rows".
One approach that should I think work is to restrict the output range of your formula. So for example if you wish it to apply to 100 rows, use:
=array_constrain(ARRAYFORMULA(IF(E2:E>0,IF(D2:D=0,"Need Due Date",""),"")),100,1)
However the problem you mention and the error message I saw are both because it is an array formula. There seems little need for it to be such and something like:
=if(and(D2=0,E2>0),"Need Due Date",)
is much faster, specially for a large number of rows, though unlike the array version does require copying down.

Array.Clear throwing out of bounds exception

I'm having trouble with a clear statement. I've got an array that gets sized dynamically, filled, and then passed to a function to be converted to some custom objects.
After that conversion I want to clear the array. I use
Array.Clear(FileData, 0, FileData.Length)
as this thread suggests (reset-an-array-to-default-in-visual-basic). However, every time I get to that point in the script the try-catch wrapping the Clear catches an out of bounds exception on the Clear.
The array is not empty (actually it's got ~34900 items) so it's not that the array has zero length. The one thing that it might be that isn't discussed in the question I referenced above is that my array is 2 dimensional.
All that said, I'm fairly well stumped. Any help would be appreciated.
UPDATE: For those experiencing this issue, I ultimately just left the step commented out, so that instead of clearing and then setting the array to Nothing, I just set it to Nothing. Doesn't really solve the underlying issue, but (should) free up memory all the same.

Resources