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 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Image Analyst
Image Analyst el 25 de Nov. de 2017
Editada: Image Analyst el 25 de Nov. de 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 comentarios
Tien Quach
Tien Quach el 26 de Nov. de 2017
Is there any way that I can display the question straight to the command window instead of a pop-up question? Just can asking because I think you have a really good way to do it.
Walter Roberson
Walter Roberson el 26 de Nov. de 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

Iniciar sesión para comentar.

Más respuestas (1)

Asfia
Asfia el 6 de Dic. de 2025 a las 18:32
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 comentario
Walter Roberson
Walter Roberson el 6 de Dic. de 2025 a las 20:31
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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by