How to fill in missing rows in a Matrix

2 views (last 30 days)
Hey Guys,
i have a big matrix like so:
-1 0.5 0.0
-1 0.5 0.02
-1 0.5 0.04
...
-1 0.5 1.5
-1 0.45 0.0
-1 0.45 0.02
...
and so on.
In some rows the third column stops before it reaches 1.5.
Is there a way that i can detect where the numeration has stopped and in the second step, am I able to insert the missing Data?
For your aknowledgment, there are more columns after the third one, they could be empty oder filled with zeros.
Thanks in regards for your help!
  2 Comments
Jan
Jan on 22 Jan 2019
There are no empty elements in a matrix.
madhan ravi
madhan ravi on 22 Jan 2019
Second Jan , plus lookinto fillmissing() .

Sign in to comment.

Accepted Answer

Jan
Jan on 22 Jan 2019
Edited: Jan on 22 Jan 2019
% Create the full array manually:
v = (0:0.02:1.5).';
k = [0.5, 0.45].'; % I cannot guess which values you have here
M(:, 2:3) = [repelem(k, numel(v), 1), repmat(v, numel(k), 1)];
M(:, 1) = -1;
% Find matching rows and insert the full rows:
[match, index] = ismember(M, YourMatrix(:, 1:3), 'rows');
M(match, :) = YourMatrix(index(match), :);

More Answers (2)

Walter Roberson
Walter Roberson on 22 Jan 2019
mask = diff(YourMatrix(:,2)).' < 0;
jump_idx = find(mask);
val_at_jump = YourMatrix(jump_idx, 2);
too_short = find(val_at_jump ~= 1.5);
where_to_insert = jump_idx(too_short);

drano1405
drano1405 on 22 Jan 2019
Thanks for the answers Guys!
I really appreciate your help. Many Thanks to you both.

Categories

Find more on Optimization in Help Center and File Exchange

Tags

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!