How to ask the user which column data in excel is the independent data? If yes, save 1st column as x-data, and 2nd column as y-data. If no, save 2nd column as x-data, and 1st column as y-data.
5 views (last 30 days)
Show older comments
Tien Quach
on 25 Nov 2017
Commented: Walter Roberson
on 6 Dec 2025 at 20:31
clear
clc
a = first column;
b = second column;
var = xlsread('T.xlsx');
A = input('Is your first column as the independent data: ');
if strcmp(A,'YES') || strcmp(A,'yes') || strcmp(A,'Yes') || strcmp(A,'Y')
elseif
0 Comments
Accepted Answer
Image Analyst
on 25 Nov 2017
Edited: Image Analyst
on 25 Nov 2017
Try this:
message = sprintf('Which Column is x');
buttonText = questdlg(message, 'Column for x?', '1', '2', '1');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(buttonText, '1')
x = var(:, 1);
y = var(:, 2);
else
x = var(:, 2);
y = var(:, 1);
end
2 Comments
Walter Roberson
on 26 Nov 2017
ButtonText = input('Column for x? 1 or 2?');
if ButtonText == 1
x = var(:, 1);
y = var(:, 2);
else
x = var(:, 2);
y = var(:, 1);
end
More Answers (1)
Asfia
about 2 hours ago
clc; clear; close all;
%% -------- USER INPUT SECTION -------- %%
Ac = input('Enter Carrier Amplitude (Ac): '); % e.g., 1
fc = input('Enter Carrier Frequency fc (Hz): '); % e.g., 1000
bit_rate = input('Enter Bit Rate (bps): '); % e.g., 100
fs = input('Enter Sampling Frequency fs (Hz): '); % e.g., 100000
A1 = input('Enter ASK Amplitude for bit 1 (A1): '); % e.g., 1
A0 = input('Enter ASK Amplitude for bit 0 (A0): '); % e.g., 0
bits = input('Enter bit sequence (e.g., [1 0 1 1 0]): ');
%% -------- TIME & MESSAGE SIGNAL -------- %%
Tb = 1 / bit_rate; % Bit duration
t = 0:1/fs:Tb*length(bits); % Time vector
m = zeros(size(t)); % Message signal
samples_per_bit = round(Tb * fs); % Samples per bit
% Build digital bit waveform
for k = 1:length(bits)
idx_start = (k-1)*samples_per_bit + 1;
idx_end = min(k*samples_per_bit, length(t));
m(idx_start:idx_end) = bits(k);
end
%% -------- CARRIER & ASK MODULATION -------- %%
c = Ac * cos(2*pi*fc*t); % Carrier
A = A0 + (A1 - A0)*m; % ASK amplitude switching
s = A .* c; % ASK signal
%% -------- ENVELOPE DETECTION -------- %%
env = abs(hilbert(s)); % Envelope
[b,a] = butter(4, bit_rate*2/fs); % Low-pass filter
demod_env = filtfilt(b,a,env);
demod_env = demod_env > 0.5; % Threshold decision
%% -------- COHERENT DETECTION -------- %%
prod = s .* (2*cos(2*pi*fc*t)); % Multiply with carrier
[b2,a2] = butter(4, bit_rate*2/fs);
coh = filtfilt(b2,a2,prod);
coh = coh > 0.2; % Binary decision
%% -------- PLOTTING -------- %%
figure('Name','ASK Modulation and Demodulation');
subplot(5,1,1);
plot(t, m, 'm', 'LineWidth',1.2);
title('Message Signal'); grid on;
subplot(5,1,2);
plot(t, c, 'b', 'LineWidth',1);
title('Carrier Signal'); grid on;
subplot(5,1,3);
plot(t, s, 'k', 'LineWidth',1);
title('ASK Modulated Signal'); grid on;
subplot(5,1,4);
plot(t, demod_env, 'g', 'LineWidth',1.2);
title('Envelope Demodulated Output'); grid on;
subplot(5,1,5);
plot(t, coh, 'r', 'LineWidth',1.2);
title('Coherent Demodulated Output'); grid on;
1 Comment
Walter Roberson
28 minutes ago
This does not seem to answer the question that was asked.
If you are asking us to test the code for you, we will need to know what kind of input values are reasonable, and what you expect to see.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!