This question already has answers here:
Fortran splats my output to asterisks - why?
(1 answer)
Need help with output of asterisks and indexes using arrays
(2 answers)
Closed 1 year ago.
I am trying to write a 2D matrix with big real numbers to file in the 2D matrix form, matrix looks as shown in the following image, also, the matrix can be download from here (link), I am using the following code, for writing to file,
write(6,*) mat_var_name
do i=1,nrows
write(6, '(*(1000F14.7))')real(mat_var(i,:ncols))
enddo
The above code works fine, when writing matrices with small values, as showing in the following image, but it is not working when writing big real numbers,
Could you suggest a solution to write 2D matrices with big real numbers to an external file,
Edit after #ian-bush and #vladimir-f comments,
Thanks for your support, write(6, '(*(F30.7))')real(mat_var(i,:ncols)) is working, I am getting the desired result as follows,
Related
This question already has an answer here:
Add a row to a matrix in OpenCV
(1 answer)
Closed 5 years ago.
Can alyone tell me how to append a couple of rows (as a cv::Mat) at the end of an existing cv::Mat? since it is a lot of data, I don't want to go through the rows with a for-loop and add them one-by-one. So here is what I want to do:
cv::Mat existing; //This is a Matrix, say of size 700x16
cv::Mat appendNew; //This is the new Matrix with additional data, say of size 200x16.
existing.push_back(appendNew);
If I try to push back the smaller matrix, I get an error of non-matching sizes:
OpenCV Error: Sizes of input arguments do not match
(Pushed vector length is not equal to matrix row length)
So I guess .push_back() tries to append the whole matrix like a kind of new channel, which won't work because it is much smaller than the existing matrix. Does someone know if the appending of the rows at the end of the existing matrix is possible as a whole, not going through them with a for-loop?
It seems like an easy question to me, nevertheless I was not able to find a simple solution online... So thanks in advance!
Cheers:)
You can use cv::hconcat() to append rows, either on top or bottom of a given matrix as:
import cv2
import numpy as np
box = np.ones((50, 50, 3), dtype=np.uint8)
box[:] = np.array([0, 0, 255])
sample_row = np.ones((1, 50, 3), dtype=np.uint8)
sample_row[:] = np.array([255, 0, 0])
for i in xrange(5):
box = cv2.vconcat([box, sample_row])
===>
For visualization purposes I have created a RGB matrix with red color and tried to append Blue rows to the bottom, You may replace with original data, Just make sure that both the matrices to be concatenated have same number of columns and same data type. I have explicitly defined the dtype while creating matrices.
As written in title, i want to solve Ax=b.
When creating A with cv::Mat and my needed dimensions of (10 million x 5 million entries) the allocation of this storage will (obviously) fail :-D.
Instead I want to use cv::SparseMat cause every row has only two entries (1 or -1) this should be the right way to go.
But how is it possible to solve Ax=b using OpenCV and SparseMat?
With cv::Mat this is done using cv::solve(A,b,x, Solver) but it wont work (its not a correct input argument of type cv::InputArray) with cv::SparseMat any ideas how I can solve x using OpenCV (3.1.0)?
This question already has answers here:
How do I generate an image from a matrix (with floating point entries)
(2 answers)
Closed 8 years ago.
1.I have matrix 180*200 of intensity values.
2.I want image which represent this intensity values.
I don't have MATLAB on this machine (or any of your input) so I can't test. But I think this is what you're looking for
http://www.mathworks.com/help/images/ref/mat2gray.html
(Google is your friend)
The relevant code to you is:
I = mat2gray(A)
where A is the matrix containing your information
I'm using FFTW to analyze elevation data, but I started out just by looking at a simple 1D fft to make sure I had everything working. It seems to work except for the normalization (scale) factors, which I can't figure out from the documentation, mostly because my numbers are ridiculously large. For example, when I tried to just take an fft of a cosine wave
1 6.12323e-017 -1 -1.83697e-016 1 3.06162e-016 -1 -4.28626e-016 1 5.51091e-016 -1 -2.44991e-015 etc...
I got the transform to be
4.33743e-013 1.06036e+267 3.25205e+265 1.05963e+267 6.49675e+265 1.05743e+267 9.72679e+265 1.05379e+267 1.29349e+266 1.04869e+267 1.61138e+266 1.04216e+267 etc...
eg, ridiculously huge numbers.
Any help would be appreciated.
You are FFT-ing complex numbers, but you initialized your array as normal (without imaginary part) array.
I went ahead onto their side, and found out that there are NEW functions that provide double to complex and complex to double fft-ing. Neat-o!
Here: http://www.fftw.org/doc/New_002darray-Execute-Functions.html
I am trying to do a 2D Real To Complex FFT using CUFFT.
I realize that I will do this and get W/2+1 complex values back (W being the "width" of my H*W matrix).
The question is - what if I want to build out a full H*W version of this matrix after the transform - how do I go about copying some values from the H*(w/2+1) result matrix back to a full size matrix to get both parts and the DC value in the right place
Thanks
I'm not familiar with CUDA, so take that into consideration when reading my response. I am familiar with FFTs and signal processing in general, though.
It sounds like you start out with an H (rows) x W (cols) matrix, and that you are doing a 2D FFT that essentially does an FFT on each row, and you end up with an H x W/2+1 matrix. A W-wide FFT returns W values, but the CUDA function only returns W/2+1 because real data is even in the frequency domain, so the negative frequency data is redundant.
So, if you want to reproduce the missing W/2-1 points, simply mirror the positive frequency. For instance, if one of the rows is as follows:
Index Data
0 12 + i
1 5 + 2i
2 6
3 2 - 3i
...
The 0 index is your DC power, the 1 index is the lowest positive frequency bin, and so forth. You would thus make your closest-to-DC negative frequency bin 5+2i, the next closest 6, and so on. Where you put those values in the array is up to you. I would do it the way Matlab does it, with the negative frequency data after the positive frequency data.
I hope that makes sense.
There are two ways this can be acheived. You will have to write your own kernel to acheive either of this.
1) You will need to perform conjugate on the (half) data you get to find the other half.
2) Since you want full results anyway, it would be best if you convert the input data from real to complex (by padding with 0 imaginary) and performing the complex to complex transform.
From practice I have noticed that there is not much of a difference in speed either way.
I actually searched the nVidia forums and found a kernel that someone had written that did just what I was asking. That is what I used. if you search the cuda forum for "redundant results fft" or similar you will find it.