How can I limit the load function?

3 views (last 30 days)
Martin Mittrenga
Martin Mittrenga on 13 Aug 2022
Commented: Star Strider on 13 Aug 2022
Hello, I am evaluating some external lists in Matlab. For this I import the signals with load('voyager_output_real.dat'); Etc. Since one signal only contains 1249 values, I am looking for a solution to limit all imported signals to 1249 values when loading. How can I do this quickly and easily?
I need that limit for the better view of plot. Thanks
My Code:
c
lose all;
clear all;
load('voyager_output_real.dat'); %10000 Values
load('voyager_signal_ideal.mat'); %Only 1249 Values
figure;
plot(voyager_output_real,'b-','linewidth',2);
hold on;
plot(voyager_signal_ideal,'r-','linewidth',2);
grid;
ylabel('Skalierungsfaktor');
xlabel('Samples');

Answers (2)

Star Strider
Star Strider on 13 Aug 2022
I am not certain what you want, however one option is to Load List of Variables into Structure Array You can then limit the values.
Example —
x = 0:9999;
y = sin(2*pi*x/1000);
figure
plot(x, y)
grid
xline(1249,'--r')
save('test1.mat', 'x', 'y')
LD = load('test1.mat')
LD = struct with fields:
x: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 … ] y: [0 0.0063 0.0126 0.0188 0.0251 0.0314 0.0377 0.0440 0.0502 0.0565 0.0628 0.0691 0.0753 0.0816 0.0879 0.0941 0.1004 0.1066 0.1129 0.1191 0.1253 0.1316 0.1378 0.1440 0.1502 0.1564 0.1626 0.1688 0.1750 0.1812 0.1874 0.1935 0.1997 0.2059 0.2120 … ]
xv = LD.x(1:1249);
yv = LD.y(1:1249);
figure
plot(xv, yv)
grid
xlim([min(xv) max(xv)])
Experiment to get the result you want.
.
  2 Comments
Martin Mittrenga
Martin Mittrenga on 13 Aug 2022
Hello Star Strider, thanks for your response.
I really just want from load('voyager_output_real.dat'); read in the first 1249 values, otherwise my scaling in the plot will slip.
Star Strider
Star Strider on 13 Aug 2022
I understand that, however I do not have those data to experiment with.
My code example loads the entire record, then assigns only the range of interest to the data vectors. You can then specifically clear the ‘LD’ variables if you want to. (I did not see any specific reason to do that.) The ‘xv’ and ‘yv’ variables (in my code example) will remain in the workspace.
I am not certain that you can use load with the .dat files, since I have no idea what is in them. I would still load them into a structure and then deal with them there.

Sign in to comment.


Walter Roberson
Walter Roberson on 13 Aug 2022
In some cases, you can use matfile to access parts of a variable without loading the entire variable.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!