What variable can I put into find()?
Show older comments
I'm struggling to figure out what variable to put into find(). The goal is to put in the mouses x-cordinate location into the graph with the goal of extracting ALL of the correlating y values for the row#. I will post the code below.
This is the working code:
%clear
clear;
%recieve file
%have user select a file with pop up window
%Can only grab CSV files
[file,path,indx] = uigetfile(".csv", 'Select a file');
%modify with opts to get rid of NaNs
opts = detectImportOptions(file);
opts = setvartype(opts, 'char');
%read the table
data = readtable(file,opts);
%get the number of rows and columns
numRows = height(data);
numCols = width(data);
%extracting Header titles for describing the frequency that the antennas are
%Transmitting and recieving at.
titleTx = data{1,1};
titleTxValue=data{1,2};
titleHz=data{1,3};
titleRx=data{2,1};
titleRxValue=data{2,2};
titleHz2=data{2,3};
%Turn 1x1 cell arrays into strings in order to make title
titleTxString = char(titleTx);
titleTxValueString = char(titleTxValue);
titleHzString = char(titleHz);
titleRxString = char(titleRx);
titleRxValueString = char(titleRxValue);
titleHz2String = char(titleHz2);
%Combine title values in order to put in one line on graph
titleCombo = {titleTxString ,titleTxValueString,titleHzString, titleRxString, titleRxValueString, titleHz2String};
str = strjoin(titleCombo);
%generate figure
f1 = figure(1);
cla; hold on; grid on;
xAxisTitleFreq = data{3,1};
xAxisDataFreq = cellfun(@str2num,data{4:end,1});
%for loop for generating data under headers i.e(frequency, EMI, etc.)
for i=2:numCols
%Extract data from readData
%converts yaxisDataPwr string to a double
yAxisDataPwr = str2double(data{4:end,i});
%grab data for legend
legendHeaderNames = char(data{3,i});
%Plot data
plot(xAxisDataFreq, yAxisDataPwr,'DisplayName', legendHeaderNames);
end
%data Cursor mode, this allows the data point closest to the cursor to be
%displayed after the user clicks the left mouse button.
dcm = datacursormode;
dcm.Enable = 'on';
dcm.DisplayStyle = 'window';
%labeling x&y axis and title
% y-axis is is db but some data points are in dBM, may need to go back and
% try and modify IDK tho.
title(str);
xlabel(xAxisTitleFreq);
ylabel("dB");
lgd=legend;
legend show;
%modifies the number of columns in the legend
lgd.NumColumns = 3;
This is the code that I am trying to add, the issue is that MATLAB isn't recognizing C(1,1) as a variable (which i'm pretty sure is the x cordinate of the mouse location).
%generates table, will use for interperlation
bTest = data{4:end,1:end};
%Take firsrt column (frequency values) from bTest
firstCol = bTest(:,1);
%find still figuring this out
k=find(C(1,1)<firstCol(end));
m=[k(end),k(end)+1];
%Testing purposes: trying to get a and y cordinates
fig2 = uifigure;
holder = [0,0];
tab = uitable(fig2,'Data',holder,'ColumnName',{'X Coord','Y Coord'});
set (gcf, 'WindowButtonMotionFcn', {@mouseMove,tab});
function mouseMove (src,event,tab)
C = get (gca, 'CurrentPoint');
title(gca, ['(X,Y) = (', num2str(C(1,1)), ', ',num2str(C(1,2)), ')']);
MousePt = [C(1,1),C(1,2)];
tab.Data = MousePt;
end
ANY help would be greatly appreciated!
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Object Properties 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!