Import and reshape the data
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Brave A
el 5 de Sept. de 2022
Comentada: Walter Roberson
el 6 de Sept. de 2022
I have 20000 data(in attachment) and data is in groups of 10 -- the data starts at 0 and returns to 0 each 10 entries.
I needs to plot them so I tried
readmatrix('trans_bad.txt', 'delimiter', '\t');
but it's not working. so I tried this one
r3 = importdata('trans_bad.txt');
ro = mean(reshape(r3,40,[]), 1);
ro = ro';
ys_03 =ro(1:max_iterations, 1);
plot(xs, ys_03);
not sure if my way is correct because the curve dropped into 0. Any suggestions?
thanks in advance!
2 comentarios
Respuesta aceptada
Image Analyst
el 5 de Sept. de 2022
Looks like it's 0 every 20 elements, not 10.
Try this:
data = importdata('trans_bad.txt');
% Reshape into 20 by 1000 matrix.
data2 = reshape(data', 20, [])
[rows, columns] = size(data2)
for row = 1 : rows
plot(data2(row, :), '-');
hold on;
end
grid on;
15 comentarios
Image Analyst
el 6 de Sept. de 2022
I tried this:
data = importdata('trans_bad.txt');
% Reshape into 20 by 1000 matrix.
data2 = reshape(data', 20, [])
[rows, columns] = size(data2)
means = mean(data2, 1);
plot(means, 'b-', 'LineWidth', 2);
grid on;
What, exactly, is wrong with that? I know it doesn't match the picture you posted, but the picture you posted does not match what you're saying in words using the data you provided.
Walter Roberson
el 6 de Sept. de 2022
Is there any other command instead of reshaping like taking windows size?
Yes, you could use blkproc() to request to process 20 (or 40) samples at a time. The function is intended primarily for image processing, but there is no inherent reason why you could not use it for other block operations.
However, really if reshape() and mean() is not serving your needs, then I really doubt that blkproc() would be any more satisfactory, and using it would tend to obscure what you are doing. At this point I would suggest you use a for loop, like
for idx = 1 : 20 : numel(data)-19
thissegment = data(idx:idx+19);
%do something appropriate with the data in thissegment
end
This will provide clarity to you that the problem is not reshape() but rather a problem with your data or with your expectations.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!