Indexing a variable in a cell array?

3 ビュー (過去 30 日間)
Peyton FitzGerald
Peyton FitzGerald 2021 年 7 月 28 日
コメント済み: Peyton FitzGerald 2021 年 7 月 28 日
I am a college-level mechanical engineer writing (what I thought was) basic software for a small cabinet installation company. My program starts by reading two Excel spreadsheets that have job information stored in strings and numbers, and then converts them into string arrays:
[nums1, txt1]=xlsread('Job_Information');
[nums2, txt2]=xlsread('Subjob_Information');
txt1=string(txt1);
txt2=string(txt2);
The program then asks the user to input a date, and I want the program to find and index the subjobs that have the corresponding dates:
fprintf('To begin, enter a date in the mm/dd/yyyy format:');
date=input(' ','s');
So it saves the input date as a string, and I want to compare that string to what is stored in the cell array, kind of like so:
find(txt2==date);
I know that isn't the correct syntax, but I hope that better illustrates my problem. Thanks in advance!

回答 (1 件)

Stephen23
Stephen23 2021 年 7 月 28 日
編集済み: Stephen23 2021 年 7 月 28 日
strcmpi(txt2,date)
But...
  • you should be using READTABLE to import that file data,
  • and handle those dates as DATETIME, not as text.
  1 件のコメント
Peyton FitzGerald
Peyton FitzGerald 2021 年 7 月 28 日
Thank you very much! That all worked!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by