Use CVX and Matpower in Matlab Online

28 views (last 30 days)
Diana Vazquez Romo
Diana Vazquez Romo on 18 Dec 2018
Commented: Walter Roberson on 29 Apr 2023
Hi everyone,
I would like to use Matlab however I can't download the software on my computer as I do not have admin rights.
Thus I am using Matlab Online. I would like to use CVX and Matpower and was wondering what is the best way to do so.
I know that to install CVX you must download the zip folder, extract it, navigate to it on Matlab and run the cvx_setup command. I thought about doing this on Matlab Online. I'd just download the folder into Matlab Drive and navigate to it on Matlab Online.
However.... this drive only allows for file downloads. So if I'd want to download the CVX folder I'd have to download file by file while making sure file hiearchies are intact (I think this last part is necessary for CVX to run properly). The same goes for Matpower.
Any suggestions?
Thank You
-Diana
  4 Comments
Deep Kiran
Deep Kiran on 28 May 2021
Hi Diana,
Can you please write the steps for running these two for online matlab?
Thanks
Gian Albert Alfani
Gian Albert Alfani on 8 Jun 2021
@Deep Kiran Download linux version and upload to drive. then just setup

Sign in to comment.

Answers (1)

swapnil
swapnil on 29 Apr 2023
% Define the signal as a combination of 4 harmonics
t = linspace(0, 10, 5000);
x = 0.2*cos(2*pi*t) + 0.5*sin(4*pi*t) + 0.35*cos(16*pi*t);
% Plot the original signal
figure;
plot(t, x);
title('Original Signal');
% Sample the signal
fs = 120; % Minimum sampling frequency = 2*16 Hz
Ts = 1/fs;
n = floor(10/Ts);
ts = linspace(0, 10, n);
xs = 0.2*cos(2*pi*ts) + 0.5*sin(4*pi*ts) + 0.35*cos(16*pi*ts);
% Plot the samples
figure;
stem(ts, xs);
title('Sampled Signal');
% Compute the DCT of the signal
d = dct(x);
% Compute the norm zero of the DCT
norm0_dct = nnz(d == 0);
% Plot the DCT of the signal
figure;
stem(d);
title('DCT of Signal');
% Define the measurement matrix phi
m = 100; % Number of measurements
phi = randn(m, length(x));
% Measure the DCT in the form of y = phi * d
y = phi * d;
% Solve the convex optimization problem to recover d
cvx_begin
variable d_hat(length(x))
minimize(norm(d_hat, 1))
subject to
phi * d_hat == y
cvx_end
% Plot the recovered DCT of the signal
figure;
stem(d_hat);
title('Recovered DCT of Signal');
% Find the inverse DCT of the recovered signal
x_hat = idct(d_hat);
% Plot the reconstructed signal
figure;
plot(t, x, 'b', t, x_hat, 'r');
title('Reconstructed Signal');
legend('Original', 'Recovered');
% Increase the number of rows in phi
m = 500; % Number of measurements
phi = randn(m, length(x));
y = phi * d;
cvx_begin
variable d_hat(length(x))
minimize(norm(d_hat, 1))
subject to
phi * d_hat == y
cvx_end
x_hat = idct(d_hat);
figure;
plot(t, x, 'b', t, x_hat, 'r');
title('Reconstructed Signal (Increased Number of Rows in Phi)');
legend('Original', 'Recovered');
% Increase the sparsity of d
d_sparse = zeros(size(d));
d_sparse(1:10:end) = d(1:10:end); % Set every 10th coefficient to its original value
y = phi * d_sparse;
cvx_begin
variable d_sparse_hat(length(x))
minimize(norm(d_sparse_hat, 1))
subject to
phi * d_sparse_hat == y
cvx_end
x_sparse_hat = idct(d_sparse_hat);
figure;
plot(t, x, 'b', t, x_sparse_hat, 'r');
title('Reconstructed Signal (Increased Sparsity)');
legend('Original', 'Recovered');
% Compute the compression ratio
cr = length(x)/m;
fprintf('Compression ratio: %f\n', cr);

Communities

More Answers in the  Distance Learning Community

Categories

Find more on Platform and License in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!