matrix

Last Observation Carried Forward In a data frame? [duplicate]

好久不见. 提交于 2019-12-27 12:05:03
问题 This question already has answers here : Replacing NAs with latest non-NA value (15 answers) Closed last year . I wish to implement a "Last Observation Carried Forward" for a data set I am working on which has missing values at the end of it. Here is a simple code to do it (question after it): LOCF <- function(x) { # Last Observation Carried Forward (for a left to right series) LOCF <- max(which(!is.na(x))) # the location of the Last Observation to Carry Forward x[LOCF:length(x)] <- x[LOCF]

Array of Matrices in MATLAB

别来无恙 提交于 2019-12-27 11:15:27
问题 I am looking for a way to store a large variable number of matrixes in an array in MATLAB. Are there any ways to achieve this? Example: for i: 1:unknown myArray(i) = zeros(500,800); end Where unknown is the varied length of the array, I can revise with additional info if needed. Update: Performance is the main reason I am trying to accomplish this. I had it before where it would grab the data as a single matrix, show it in real time and then proceed to process the next set of data. I

How to convert decimals in a matrix to integers? [closed]

依然范特西╮ 提交于 2019-12-27 02:17:02
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . If my input matrix is: v = -0.7071 0.5774 0.4082 0.0000 -0.5774 0.8165 0.7071 0.5774 0.4082 The output should be: v = -1 1 1 0 -1 2 1 1 1 回答1: [A,B] = size(v) for ii = 1:B v(:,ii) = v(:,ii)./abs(min(v(:,ii))); end In case this is the exact example you have. And just in case doubles are not good

How to convert decimals in a matrix to integers? [closed]

半腔热情 提交于 2019-12-27 02:16:34
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . If my input matrix is: v = -0.7071 0.5774 0.4082 0.0000 -0.5774 0.8165 0.7071 0.5774 0.4082 The output should be: v = -1 1 1 0 -1 2 1 1 1 回答1: [A,B] = size(v) for ii = 1:B v(:,ii) = v(:,ii)./abs(min(v(:,ii))); end In case this is the exact example you have. And just in case doubles are not good

How to convert decimals in a matrix to integers? [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-27 02:16:13
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . If my input matrix is: v = -0.7071 0.5774 0.4082 0.0000 -0.5774 0.8165 0.7071 0.5774 0.4082 The output should be: v = -1 1 1 0 -1 2 1 1 1 回答1: [A,B] = size(v) for ii = 1:B v(:,ii) = v(:,ii)./abs(min(v(:,ii))); end In case this is the exact example you have. And just in case doubles are not good

221.Maximal Square

烈酒焚心 提交于 2019-12-26 15:53:43
问题描述: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example: Input: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 Output: 4 解题思路:   这道题可以用动态规划来解,为O(n 2 )的时间复杂度   建立一个二维的dp数组,里面dp[i][j]存的是可形成的以(i,j)为右下角的正方形的最长的边长。   那么dp[i][j] = min(dp[i-1][j-1], min(dp[i][j-1], dp[i-1][j]) + 1 如下图所示:    (i-1, j-1)能够形成的最大正方形为红色区域 (i-1, j)能够形成的最大正方形为红色区域+黄色区域 (i, j-1)能够形成的最大正方形为红色区域+绿色区域 若左上角不为0的话那么红色区域也会扩展至包含左上角 若(i-1, j)比红色区域要小2及其以上的话,红色区域也会缩小,因为他们很有大一部分是重叠的。 注意!因为要返回的是面积所以需要平方。 代码: class Solution { public: int maximalSquare(vector<vector<char>>&

C#矩阵运算类

只谈情不闲聊 提交于 2019-12-26 10:01:20
命名空间:matrix 定义类:Matrix 方法: public Matrix(int mm, int nn) 定义矩阵A: Matrix A=new Matrix(int mm, int nn); public double read(int i, int j) 获取Aij: A.read(i,j); public int write(int i, int j, double val) 将数据b写入Aij: A.read(i,j,b); 释放矩阵: public void freeMatrix() A.freeMatrix(); 方法: //C = A + B //成功返回1,失败返回-1 public int add(ref Matrix A, ref Matrix B, ref Matrix C) //C = A - B //成功返回1,失败返回-1 public int subtract(ref Matrix A, ref Matrix B, ref Matrix C) //C = A * B //成功返回1,失败返回-1 public int multiply(ref Matrix A, ref Matrix B, ref Matrix C) //行列式的值,只能计算2 * 2,3 * 3 //失败返回-31415,成功返回值 public double det(ref

LOJ 6485 LJJ学多项式

瘦欲@ 提交于 2019-12-26 01:19:00
前言 蒟蒻代码惨遭卡常,根本跑不过 前置芝士——单位根反演 单位根有这样的性质: \[ \frac{1}{n}\sum_{i=0}^{n-1}\omega_{n}^{ki}=\left[n|k\right] \] 所以可以得出单位根反演的式子 如果有 \(f(x)=\sum_{i=0}a_ix^i\) ,就可以推出 \[ \sum_{i=0}^na_i\left[d|i\right]=\frac{1}{d}\sum_{p=0}^{d-1}f(\omega_d^p) \] 证明可以把上面的式子代入,然后交换和号 思路 这道题要求的东西是这样的 \[ \sum_{i=0}^3a_i\sum_{j=0}^n\left(\begin{matrix}n\\j\end{matrix}\right)s^j\left[j\%4=i\right] \] 写出 \(\sum_{j=0}^n\left(\begin{matrix}n\\j\end{matrix}\right)s^j\) 的生成函数,由二项式定理得到是 \((sx+1)^n\) 不妨设i=0 则要求 \[ \sum_{j=0}^n\left(\begin{matrix}n\\j\end{matrix}\right)s^j\left[4|j\right] \] 直接套公式 原式等于 \[ \frac{1}{4}\sum_{p=0}^3f(

How to plot n dimmensional matrix?

情到浓时终转凉″ 提交于 2019-12-25 20:07:04
问题 I want to visualize my matrix with the computed mean of that matrix. And I want to plot that points and the mean at the same window. here is my Matrix and the Mean Input=4 1 1 3 9 0 2 5 5] Average=mean(Input How to plot it?? To plott figure I using this command: plot(InputMatrix(:,:,:),Average'*'); There are 9 points, but I just need 3 points from matrix and 1 point of the mean... 1st point from -->4 3 2 2nd point from -->1 9 0 3rd point from -->1 0 5 the 4th point is -->the mean / average

How to plot n dimmensional matrix?

痞子三分冷 提交于 2019-12-25 20:05:10
问题 I want to visualize my matrix with the computed mean of that matrix. And I want to plot that points and the mean at the same window. here is my Matrix and the Mean Input=4 1 1 3 9 0 2 5 5] Average=mean(Input How to plot it?? To plott figure I using this command: plot(InputMatrix(:,:,:),Average'*'); There are 9 points, but I just need 3 points from matrix and 1 point of the mean... 1st point from -->4 3 2 2nd point from -->1 9 0 3rd point from -->1 0 5 the 4th point is -->the mean / average